Results 1 to 4 of 4
Thread: Password
- 09-19-2010, 11:22 PM #1
Member
- Join Date
- Aug 2010
- Posts
- 70
- Rep Power
- 0
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; } }
- 09-20-2010, 12:11 AM #2
Member
- Join Date
- Sep 2010
- Posts
- 2
- Rep Power
- 0
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:
It can became crazy-complex, but if you know how to use them, I've found Regex to very useful and powerful.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]).*$
- 09-20-2010, 12:27 AM #3
Member
- Join Date
- Aug 2010
- Posts
- 70
- Rep Power
- 0
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.
- 09-20-2010, 10:43 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Similar Threads
-
'Password' help
By iWonder in forum New To JavaReplies: 20Last Post: 12-17-2008, 10:05 PM -
how to check password for 3 times enterd wrong password
By sk.mahaboobbhasha@gmail.c in forum New To JavaReplies: 2Last Post: 11-14-2008, 07:53 PM -
how to check password for 3 times enterd wrong password
By sk.mahaboobbhasha@gmail.c in forum Java ServletReplies: 0Last Post: 11-14-2008, 01:22 PM -
password ?!
By jon80 in forum New To JavaReplies: 9Last Post: 11-14-2008, 01:19 PM -
How to check password of a jsp/html with the password of Database(mysql) #1
By sk.mahaboobbhasha@gmail.c in forum Java ServletReplies: 2Last Post: 11-14-2008, 01:11 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks