Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-23-2008, 05:13 PM
Member
 
Join Date: Jun 2008
Posts: 11
buzzdsm is on a distinguished road
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.

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;
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-23-2008, 07:08 PM
serjant's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Ukraine,Zaporozhye
Posts: 338
serjant is on a distinguished road
Send a message via ICQ to serjant Send a message via Skype™ to serjant
For checking one upper case here is the method:

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:

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:
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:
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; }
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 06-23-2008, 07:54 PM
fishtoprecords's Avatar
Senior Member
 
Join Date: Jun 2008
Posts: 476
fishtoprecords is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 06-23-2008, 08:00 PM
Nicholas Jordan's Avatar
Senior Member
 
Join Date: Jun 2008
Location: Southwest
Posts: 789
Nicholas Jordan is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
password ?! jon80 New To Java 9 11-14-2008 03:19 PM
Password System help quickfingers New To Java 1 06-23-2008 08:18 PM
Asking for password from a Servlet Java Tip Java Tips 0 01-27-2008 10:05 PM
add password to folder ismailsaleh AWT / Swing 1 01-08-2008 07:46 AM
Problem with a password saytri New To Java 2 12-27-2007 01:06 PM


All times are GMT +3. The time now is 02:01 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org