Results 1 to 3 of 3
  1. #1
    rickw is offline rick
    Join Date
    Apr 2012
    Location
    California, US
    Posts
    1
    Rep Power
    0

    Default Password validation help

    I have some code that currently checks for minimum and maximum length for user's password when they create or edit their password. I want to add something that will also require uppercase, lowercase, special char, and numeric. Any suggestions on what to add to this or where I can find some information or examples? I've been Googling and trying to add to this to add additional password requirements and have been unsuccessful.

    This is what I want to require.

    At least eight characters in length
    No more than 20 characters in length
    at least lower-case letter and one upper-case
    at least one special character from: !@#$%^&*()~`-=_+[]{}|:";',./<>?
    at least one number [0-9] character
    Cannot match the account login name or email address

    My current password validation code

    public static final int MIN_PASSWORD_LENGTH = 8;
    public static final int MAX_PASSWORD_LENGTH = 20;

    public static boolean isAcceptablePassword(String password)
    {
    if(TextUtils.isEmpty(password))
    return false;

    int len = password.length();

    if(len < MIN_PASSWORD_LENGTH || len > MAX_PASSWORD_LENGTH)
    return false;

    for(int i = 0; i < len; i++)
    {
    char c = password.charAt(i);
    if (Character.isWhitespace(c))
    return false;
    }

    return true;
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: Password validation help

    Look around the FAQa of the site and discover how to post code so that it retains its formatting.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,562
    Rep Power
    25

    Default Re: Password validation help

    Use some boolean variables to keep track of all the features you want.
    Scan the String char by char and set the variables as each feature is found.
    At the end of the scan, check that all the required features have been found by testing the variables
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. how to give error message after validation of username and password
    By trupesh1991 in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 01-17-2012, 11:54 AM
  2. Simple password validation.
    By DarkAlex in forum New To Java
    Replies: 27
    Last Post: 03-21-2011, 01:28 AM
  3. user name and password validation
    By exose in forum New To Java
    Replies: 6
    Last Post: 01-20-2011, 02:59 PM
  4. 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
  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
  •