Results 1 to 4 of 4
  1. #1
    buzzdsm is offline Member
    Join Date
    Jun 2008
    Posts
    11
    Rep Power
    0

    Default 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;

  2. #2
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    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:

    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;
    	  }
    And for at least one appearance of digit in the String:
    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;
    	  }
    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 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;
    }

  3. #3
    fishtoprecords's Avatar
    fishtoprecords is offline Senior Member
    Join Date
    Jun 2008
    Posts
    571
    Rep Power
    7

    Default

    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.

  4. #4
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    8

    Default

    I have a common password rejection class already written. Passphrases are easier for people to remember. Often, I will get a totally random string. People laugh at me for that, but I sleep well at night.

Similar Threads

  1. password ?!
    By jon80 in forum New To Java
    Replies: 9
    Last Post: 11-14-2008, 02:19 PM
  2. Password System help
    By quickfingers in forum New To Java
    Replies: 1
    Last Post: 06-23-2008, 07:18 PM
  3. Asking for password from a Servlet
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-27-2008, 09:05 PM
  4. add password to folder
    By ismailsaleh in forum AWT / Swing
    Replies: 1
    Last Post: 01-08-2008, 06:46 AM
  5. Problem with a password
    By saytri in forum New To Java
    Replies: 2
    Last Post: 12-27-2007, 12:06 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
  •