Results 1 to 4 of 4

Thread: Password

  1. #1
    Adomini is offline Member
    Join Date
    Aug 2010
    Posts
    70
    Rep Power
    0

    Default Password

    Hello again everyone! Hope the weekend is good to all....

    I am trying to create a password program and I do think I am missing something so it will not run. Can someone check the logic in this program for me please?

    The password has to have at least 8 characters, at least two digits, and can only consist of letters and digits.

    Java Code:
    public static boolean isValidPassword (String s)
    	{
    		
    	    if (s == null)
    		throw new IllegalArgumentException ("null string");
    			
    			
    			boolean result = false;
    			
    			
    			if (s.length() <= 9) 
    				result = false;
    			else
    			{
    				int i = 0;
    				boolean done = false;
    				do
    				{
    					if (i == s.length())
    					{
    						result = true;
    						done = true;
    					}
    					else if (Character.isDigit(s.charAt(i))) 
    					{
    						if (s.charAt(i) > 8)
    						{
    							result = false;
    							done = true;
    						}
    					}
    					else if (!Character.isLetter(s.charAt(i)))
    					{
    						if ( s.charAt(i) > 2)
    						{
    						result = false;
    						done = true;
    						}
    					}
    					else
    						i++;			
    				}
    				while (!done);
    			}
    			return result;
    		}
    	}

  2. #2
    JavaRosie is offline Member
    Join Date
    Sep 2010
    Posts
    2
    Rep Power
    0

    Default

    You might want to look into Regular Expressions (Regex) if you do more of this sort of work. This is perfect for password validation as proven by this very helpful link:

    Password Strength Validation with Regular Expressions | Zorched / One Line Fix

    I'm sure you can find others that will help explain Regex to you, certainly better than I can, but here's one example from the site above:
    The part that makes this all interesting is that you can combine any number of assertions about the string into one larger expression that will create your rules for complexity. So if you want to match a string at least 6 characters long, with at least one lower case and at least one uppercase letter you could use something like:
    ^.*(?=.{6,})(?=.*[a-z])(?=.*[A-Z]).*$

    And if you want to throw in some extra complexity and require at least one digit or one symbol you could make a match like:
    ^.*(?=.{6,})(?=.*[a-z])(?=.*[A-Z])(?=.*[\d\W]).*$
    It can became crazy-complex, but if you know how to use them, I've found Regex to very useful and powerful.

  3. #3
    Adomini is offline Member
    Join Date
    Aug 2010
    Posts
    70
    Rep Power
    0

    Default

    True, that is very interesting. Were I a current programmer, that would work. It looks cool!

    I am doing this specific problem for homework, and have worked out the problem.

    I was kind of hoping for someone to just look at the logic and tell me where I am off.

  4. #4
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,935
    Rep Power
    19

    Default

    What is the code doing and what do you expect it to do?
    In other words what does "will not run" mean?

Similar Threads

  1. 'Password' help
    By iWonder in forum New To Java
    Replies: 20
    Last Post: 12-17-2008, 10:05 PM
  2. how to check password for 3 times enterd wrong password
    By sk.mahaboobbhasha@gmail.c in forum New To Java
    Replies: 2
    Last Post: 11-14-2008, 07:53 PM
  3. how to check password for 3 times enterd wrong password
    By sk.mahaboobbhasha@gmail.c in forum Java Servlet
    Replies: 0
    Last Post: 11-14-2008, 01:22 PM
  4. password ?!
    By jon80 in forum New To Java
    Replies: 9
    Last Post: 11-14-2008, 01:19 PM
  5. How to check password of a jsp/html with the password of Database(mysql) #1
    By sk.mahaboobbhasha@gmail.c in forum Java Servlet
    Replies: 2
    Last Post: 11-14-2008, 01:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •