Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JOptionPane;
- public class CheckPass {
- public static void main(String[] args) {
- String Password;
- boolean flag=false;
- while (flag==false) {
- Password = JOptionPane.showInputDialog(null, "1.A password must have at least eight characters.\n"
- + "2.A password consists of only letters and digits.\n"
- + "3. A password must contain at least two digits.\n\n"
- + "Supposing you agree to the above Terms and Conditions, please enter your password: ","Terms and Conditions", -1);
- if (PassValidation(Password))
- break;
- }
- JOptionPane.showMessageDialog(null,"Your password is valid!","Correct.",2);
- }
- public static boolean PassValidation(String pass) {
- int numcount=0;
- for (int i=0; i<pass.length(); i++) {
- char ch = pass.charAt(i);
- if ( (ch>='a' && ch<='z') || (ch>='A' && ch<='Z') ) {
- }
- else if ( ch>='0' && ch<='9' )
- numcount++;
- else
- return false;
- }
- if ( (pass.length()>=8) && (numcount>=2) ) return true;
- else return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement