Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: Password Strength Meter

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Password Strength Meter

    Hi to all!

    I am a beginner Java programmer. i would like to seek help on how to create a password strength meter.. the conditions are the following:

    1. must have atleast 7 characters.
    2. must contain atleast 1 number.
    3. must contain atleast 1 small letter.
    4. must contain atleast 1 capital letter.
    5. must contain atleast 1 symbol.

    thank you very much.

    Dr.Kernel


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Password Strength Meter

    What have you tried?
    Improving the world one idiot at a time!

  3. #3
    Junior Member
    Join Date
    Nov 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Password Strength Meter

    none yet.. but i found this code i dont know if this will work..

    pw_strenth.js
    // Settings
    // -- Toggle to true or false, if you want to change what is checked in the password
    var bCheckNumbers = true;
    var bCheckUpperCase = true;
    var bCheckLowerCase = true;
    var bCheckPunctuation = true;
    var nPasswordLifetime = 365;
     
    // Check password
    function checkPassword(strPassword)
    {
            // Reset combination count
            nCombinations = 0;
     
            // Check numbers
            if (bCheckNumbers)
            {
                    strCheck = "0123456789";
                    if (doesContain(strPassword, strCheck) > 0)
                    {
                            nCombinations += strCheck.length;
                    }
            }
     
            // Check upper case
            if (bCheckUpperCase)
            {
                    strCheck = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
                    if (doesContain(strPassword, strCheck) > 0)
                    {
                            nCombinations += strCheck.length;
                    }
            }
     
            // Check lower case
            if (bCheckLowerCase)
            {
                    strCheck = "abcdefghijklmnopqrstuvwxyz";
                    if (doesContain(strPassword, strCheck) > 0)
                    {
                            nCombinations += strCheck.length;
                    }
            }
     
            // Check punctuation
            if (bCheckPunctuation)
            {
                    strCheck = ";:-_=+|//?^&!.@$£#*()%~<>{}[]";
                    if (doesContain(strPassword, strCheck) > 0)
                    {
                            nCombinations += strCheck.length;
                    }
            }
     
            // Calculate
            // -- 500 tries per second => minutes
            var nDays = ((Math.pow(nCombinations, strPassword.length) / 500) / 2) / 86400;
     
            // Number of days out of password lifetime setting
            var nPerc = nDays / nPasswordLifetime;
     
            return nPerc;
    }
     
    // Runs password through check and then updates GUI
    function runPassword(strPassword, strFieldID)
    {
            // Check password
            nPerc = checkPassword(strPassword);
     
             // Get controls
            var ctlBar = document.getElementById(strFieldID + "_bar");
            var ctlText = document.getElementById(strFieldID + "_text");
            if (!ctlBar || !ctlText)
                    return;
     
            // Set new width
            var nRound = Math.round(nPerc * 100);
            if (nRound < (strPassword.length * 5))
            {
                    nRound += strPassword.length * 5;
            }
            if (nRound > 100)
                    nRound = 100;
            ctlBar.style.width = nRound + "%";
     
            // Color and text
            if (nRound > 95)
            {
                    strText = "Very Secure";
                    strColor = "#3bce08";
            }
            else if (nRound > 75)
            {
                    strText = "Secure";
                    strColor = "orange";
            }
            else if (nRound > 50)
            {
                    strText = "Mediocre";
                    strColor = "#ffd801";
            }
            else
            {
                    strColor = "red";
                    strText = "Insecure";
            }
            ctlBar.style.backgroundColor = strColor;
            ctlText.innerHTML = "<span style='color: " + strColor + ";'>" + strText + "</span>";
    }
     
    // Checks a string for a list of characters
    function doesContain(strPassword, strCheck)
     {
            nCount = 0;
     
            for (i = 0; i < strPassword.length; i++)
            {
                    if (strCheck.indexOf(strPassword.charAt(i)) > -1)
                    {
                            nCount++;
                    }
            }
     
            return nCount;
    }
    Last edited by helloworld922; November 4th, 2011 at 12:24 AM.

  4. #4
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Password Strength Meter

    Ah yes, why bother writing our own code and learning when you can simply steal it from someone else?
    Improving the world one idiot at a time!

  5. #5
    Junior Member
    Join Date
    Nov 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Password Strength Meter

    im not stealing it, im trying to analyze how he/she codes it.. just using it as my reference.

  6. #6
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Password Strength Meter

    You can achieve this by implementing a test for each of the 5 conditions.
    if password fails test 1
        return false
    if password fails test 2
        return false
    if password fails test 3
        return false
    if password fails test 4
        return false
    if password fails test 5
        return false
    return true // must have passed
    Surely test 1 is simple. How do you test if a String has 7 characters? On the other hand, if you are keen you can use a regular expression.
    Improving the world one idiot at a time!

  7. #7
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Password Strength Meter

    Quote Originally Posted by Junky View Post
    You can achieve this by implementing a test for each of the 5 conditions.
    if password fails test 1
        return false
    if password fails test 2
        return false
    if password fails test 3
        return false
    if password fails test 4
        return false
    if password fails test 5
        return false
    return true // must have passed
    Surely test 1 is simple. How do you test if a String has 7 characters? On the other hand, if you are keen you can use a regular expression.
    Adding to the Junky suggestion/comment, you can similarly test all five tests to achieve what you want to.
    Hint is compare ASCII values.

  8. #8
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Password Strength Meter

    Quote Originally Posted by Dr.Kernel
    none yet.. but i found this code i dont know if this will work..
    java != javascript. Do you wish to implement this in java, or javascript (these are java forums)

Similar Threads

  1. Auto incremented Number meter
    By sri.lakkaraju in forum Web Frameworks
    Replies: 0
    Last Post: February 25th, 2011, 05:15 AM
  2. Help with GUI Password Tester
    By java.kid21 in forum AWT / Java Swing
    Replies: 10
    Last Post: December 13th, 2010, 08:06 AM
  3. Password Tester GUI HELP
    By java.kid21 in forum Object Oriented Programming
    Replies: 3
    Last Post: December 7th, 2010, 11:35 PM
  4. Password Strength Checker
    By uthuth in forum Object Oriented Programming
    Replies: 1
    Last Post: February 6th, 2010, 04:09 PM
  5. password
    By 5723 in forum Algorithms & Recursion
    Replies: 9
    Last Post: July 9th, 2009, 05:26 AM

Tags for this Thread