Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. import javax.swing.JOptionPane;
  2.  
  3. public class CheckPass {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. String Password;
  8. boolean flag=false;
  9.  
  10. while (flag==false) {
  11. Password = JOptionPane.showInputDialog(null, "1.A password must have at least eight characters.\n"
  12. + "2.A password consists of only letters and digits.\n"
  13. + "3. A password must contain at least two digits.\n\n"
  14. + "Supposing you agree to the above Terms and Conditions, please enter your password: ","Terms and Conditions", -1);
  15. if (PassValidation(Password))
  16. break;
  17. }
  18. JOptionPane.showMessageDialog(null,"Your password is valid!","Correct.",2);
  19. }
  20.  
  21.  
  22.  
  23. public static boolean PassValidation(String pass) {
  24.  
  25. int numcount=0;
  26.  
  27. for (int i=0; i<pass.length(); i++) {
  28.  
  29. char ch = pass.charAt(i);
  30.  
  31. if ( (ch>='a' && ch<='z') || (ch>='A' && ch<='Z') ) {
  32.  
  33. }
  34.  
  35. else if ( ch>='0' && ch<='9' )
  36. numcount++;
  37.  
  38. else
  39. return false;
  40. }
  41.  
  42. if ( (pass.length()>=8) && (numcount>=2) ) return true;
  43. else return false;
  44.  
  45. }
  46.  
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement