By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,257 Members | 928 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,257 IT Pros & Developers. It's quick & easy.

Need Help with Password Program

P: 7
Hi.
I need a application where accept user password. The java program should do the following:

1. Application accept user password from keyboard
2. It has to be Less than six character and not more than ten character.
3.or it shouldnt contain at one least one letter and one digit
4. User enter password and re-enter password again to meet the requirement.
5.Password has to be matched when user entered 1st and 2nd time.

if any of you have idea about this program please contact me i need urgently this program.

thank u
Nov 15 '06 #1
Share this Question
Share on Google+
3 Replies


P: 12
Notepad work, not tested at all...
Using regular expressions might (and most likely will) be a more elegant solution...

Call the method below with the two passwords entered by the user...

Expand|Select|Wrap|Line Numbers
  1. public boolean isPasswordOk( String password1, String password2 ) {
  2.     if(!password1.equals(password2))
  3.         return false;
  4.  
  5.     if(password1.length() < 6 || password1.length() > 10 )
  6.         return false;
  7.  
  8.     char[] c = password1.toCharArray();
  9.     boolean numericOk = false;
  10.     boolean letterOk = false;
  11.     for(int i=0;i<c.length;i++) {
  12.         if(c[i].isDigit() && numericOk = false)
  13.             numericOk = true;
  14.         if(c[i].isLetter() && letterOk = false)
  15.             letterOk = true;        
  16.  
  17.         if( letterOk && numericOk )
  18.             return true;
  19.     }
  20.     return false;
  21. }
Nov 15 '06 #2

P: 12
Missed something :)
Expand|Select|Wrap|Line Numbers
  1. public boolean isPasswordOk( String password1, String password2 ) {
  2.     if(!password1.equals(password2))
  3.         return false;
  4.  
  5.     if(password1.length() < 6 || password1.length() > 10 )
  6.         return false;
  7.  
  8.     char[] c = password1.toCharArray();
  9.     boolean numericOk = false;
  10.     boolean letterOk = false;
  11.     for(int i=0;i<c.length;i++) {
  12.                 Character char = new Character(c);
  13.         if(char.isDigit() && numericOk = false)
  14.             numericOk = true;
  15.  
  16.         if(char.isLetter() && letterOk = false)
  17.             letterOk = true;        
  18.  
  19.         if( letterOk && numericOk )
  20.             return true;
  21.     }
  22.     return false;
  23. }
  24.  
Still not tested though
Have no IDE and SDK here :)
Nov 15 '06 #3

P: 7
could you please write me full program i want to whether its great or wrong. i have run the program you have told me but it didnt work.
Nov 15 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.