Results 1 to 4 of 4
Thread: Password class help
- 06-23-2008, 03:13 PM #1
Member
- Join Date
- Jun 2008
- Posts
- 11
- Rep Power
- 0
Password class help
I'm working on this project and am stuck at the bottom. Here is what I need.
The password needs to be at least 6 characters long
The password should contain at least one uppercase
The password should contain at least one lowercase
The password should contain at least one digit
Here is what I have so far.
Java Code:import java.util.Scanner: public class PasswordVerifier { public static void main(String[] args) { String password; Scanner keyboard = new Scanner(System.ini); System.out.println("Enter a password: "); password = keyboard.nextLine(); if (isValid(password)) { System.out.println("Valid password."); } else { System.out.println("Invalid password."); } } private static boolean isValid(String psWord) { boolean goodSoFar = true; int index = 0; if (psWord.length() > 6) goodSoFar = false;
- 06-23-2008, 05:08 PM #2
For checking one upper case here is the method:
Java Code:private boolean containsUpperCase(String word) { int ndx; char ch; boolean t=false; char[] letter=word.toCharArray(); for(ndx = 0; ndx < word.length(); ndx++) { ch = letter[ndx]; if (ch <='Z'&&ch>='A') { t=true; } } return t; }
For lower case:
And for at least one appearance of digit in the String:Java Code:private boolean containsLowerCase(String word) { int ndx; char ch; boolean t=false; char[] letter=word.toCharArray(); for(ndx = 0; ndx < word.length(); ndx++) { ch = letter[ndx]; if (ch <='a'+32&&ch>='z'-32) {//the same as ch>='a' && ch<='z' t=true; } } return t; }
So as you see buddy,the main work for checking letters in the String is with the ASCII table values.So in order to complete your isValide() method we di the following:Java Code:private boolean isDigit(String word) { int ndx; char ch; boolean t=false; char[] letter=word.toCharArray(); for(ndx = 0; ndx < word.length(); ndx++) { ch = letter[ndx]; if (ch <='9'&&ch>='0') { t=true; } } return t; }
Java Code:private static boolean isValid(String psWord) { boolean goodSoFar = true; int index = 0; if (psWord.length() < 6)//at least 6 characters goodSoFar = false; return goodSoFar; if(containsUpperCase(psWord)==false) goodSoFar=false; return goodSoFar; if(containsLowerCase(psWord)==false) goodSoFar=false; return goodSoFar; if(isDigit(psWord)==false) goodSoFar=false; return goodSoFar; return goodSoFar; }
- 06-23-2008, 05:54 PM #3
You realize, of course, that these rules hurt security. Users tend to use the shortest passwords that fit into the silly rules, so they use Passw0rd
You need, at least, to do a dictionary test, and properly with a variant spelling check. Using 3LET spelling doesn't really add any security.
You are better off encouraging folks to use pass phrases.
Passphrases strong enough to have any security are hard to remember, so have the user enter them often, and don't make them change them on some silly 30 day cycle.
- 06-23-2008, 06:00 PM #4
Similar Threads
-
password ?!
By jon80 in forum New To JavaReplies: 9Last Post: 11-14-2008, 01:19 PM -
Password System help
By quickfingers in forum New To JavaReplies: 1Last Post: 06-23-2008, 06:18 PM -
Asking for password from a Servlet
By Java Tip in forum Java TipReplies: 0Last Post: 01-27-2008, 08:05 PM -
add password to folder
By ismailsaleh in forum AWT / SwingReplies: 1Last Post: 01-08-2008, 05:46 AM -
Problem with a password
By saytri in forum New To JavaReplies: 2Last Post: 12-27-2007, 11:06 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks