Need Help with Password Program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • karizmatrix22
    New Member
    • Nov 2006
    • 7

    Need Help with Password Program

    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
  • soeter04
    New Member
    • Nov 2006
    • 12

    #2
    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...

    Code:
    public boolean isPasswordOk( String password1, String password2 ) {
    	if(!password1.equals(password2))
    		return false;
    	
    	if(password1.length() < 6 || password1.length() > 10 )
    		return false;
    	
    	char[] c = password1.toCharArray();
    	boolean numericOk = false;
    	boolean letterOk = false;
    	for(int i=0;i<c.length;i++) {
    		if(c[i].isDigit() && numericOk = false)
    			numericOk = true;
    		if(c[i].isLetter() && letterOk = false)
    			letterOk = true;		
    			
    		if( letterOk && numericOk )
    			return true;
    	}
    	return false;
    }

    Comment

    • soeter04
      New Member
      • Nov 2006
      • 12

      #3
      Missed something :)
      Code:
      public boolean isPasswordOk( String password1, String password2 ) {
      	if(!password1.equals(password2))
      		return false;
      	
      	if(password1.length() < 6 || password1.length() > 10 )
      		return false;
      	
      	char[] c = password1.toCharArray();
      	boolean numericOk = false;
      	boolean letterOk = false;
      	for(int i=0;i<c.length;i++) {
                      Character char = new Character(c);
      		if(char.isDigit() && numericOk = false)
      			numericOk = true;
      
      		if(char.isLetter() && letterOk = false)
      			letterOk = true;		
      			
      		if( letterOk && numericOk )
      			return true;
      	}
      	return false;
      }
      Still not tested though
      Have no IDE and SDK here :)

      Comment

      • karizmatrix22
        New Member
        • Nov 2006
        • 7

        #4
        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.

        Comment

        Working...