The following example illustrates creating a password strength checker and matcher which goes on the basis of char count and also text in the type and re-type password fields. This is just a demo and is not a great fit for real time use.
CaretListener is what i had used here. Because a CaretEvent is fired when the caret is updated. For a better understand, it is not fired when you press any of the arrow keys instead it fires when you change you press backspace and delete i.e. it is fired when caret is updated w.r.t text. CaretListener usually handles it.
jp.setValue(pw1.length()): Update the value in the progress bar with text. The maximum value of progressbar is set to 10. So it get's filled when the password length reaches 10.
if(!t.getText().isEmpty()): Enter the if-block only if the text in password text area is not empty.
if(pw1.equals(pw2)): If the text in the password field equals the text in the re-type password field, then enter the block.
jp.setString("Matched"): Print on the progress bar that passwords are matched.
jp.setStringPainted(true): The string must be visible, so true is sent. By default it is false.
jp.setString("Not Matched"): If not matched print Not Matched.
The same java code is written for the re-type password field for checking with some changes because no one knows when and on what password field user types.
This blog contains Java Tutorials, Code Samples,demonstrating several concepts in Java. All the code samples are well tested by a team of experts and hence there will be no programmatical errors. We are seamlessly thriving in making the tutorials easier for beginners.
Gowtham Gutha was a software and technology enthusiast. He is a 12th grade student and a part time blogger with extreme love in Java programming.Follow him on Google+ and Twitter or befriend him on Facebook and also on CodeProject
0 comments:
Post a Comment