Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Nov 2011
    Posts
    2
    Thanks
    0
    Thanked 1 Time in 1 Post

    Question Password validation in javascript

    function StrongPassword(Input) {
    //var re = /(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,}/; //1 number,1 Uppercase,1 lowercase,6 characters
    var re = /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])/; //1 digit,1 Uppercase,1 lowercase

    if (re.test(Input))
    {
    alert('Strong Password');
    }
    else {
    alert('Weak pwd');
    }
    }

    Help to get correct output.... both the expr will execute the else block only...

  2. Users who have thanked ssjGanesh for this post:

    phantom007 (11-01-2011)

  • #2
    New to the CF scene
    Join Date
    Oct 2011
    Posts
    3
    Thanks
    0
    Thanked 1 Time in 1 Post
    I presume you've got validate_required() function from this page: http://www.w3schools.com/js/js_form_validation.asp?

    function validate_required(field,alerttxt)
    {
    with (field)
    {
    if (value==null||value=="")
    {
    alert(alerttxt);return false;
    }
    else
    {
    return true;
    }
    }
    }
    In this case your last condition will not work as you expect it.

    You can replace it with this:

    if (password.value != cpassword.value) {
    alert("Your password and confirmation password do not match.");
    cpassword.focus();
    return false;
    }

  • Users who have thanked Eliphalet11 for this post:

    phantom007 (11-01-2011)

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,928
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    In fact a password which requires so-many lower case charcters, so-many upper-case characters, so-many digits and/or so-many special characters is less secure than the same number of characters without restriction (assuming the password spec is known to the hacker), as there are fewer possible combinations to search.

    A strong password should contain not fewer than 10 characters, and should not be restricted except to avoid a dictionary word.

    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • Users who have thanked Philip M for this post:

    phantom007 (11-01-2011)

  • #4
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,253
    Thanks
    12
    Thanked 341 Times in 337 Posts
    XKCD pretty much sums it up: http://xkcd.com/936/
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,928
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    I entirely agree with that. The best and strongest passwords which are easy to remember are made up of random ordinary words such as correcthorsebatterystaple. Or purplestarling721. Better still with words in a foreign language!

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •