Web Analytics Made Easy -
StatCounter specific characters in passwords - CodingForum

Announcement

Collapse
No announcement yet.

specific characters in passwords

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • specific characters in passwords

    I have a made a basic script for password protection but I wish to have added features. Can anyone please help.

    It must contain at least one number character
    It must contain at least one upper case character
    It must contain at least one lower case character
    It must be at least 5 but not more than 14 characters long.

    Anyone know how to script for this and where it should be put as it must be used with the prompt dialogue.

    All help much appreciated.

  • #2
    Here we go!


    function testpassword(password) {
    var flag=0;
    var pwdlength = password.length;
    if(/\d/.test(password)) { flag++} // password contains a digit
    if(/[A-Z]/.test(password)) { flag++} // password contains an uppercase letter
    if(/[a-z]/.test(password)) { flag++} // password contains a lowercase letter
    if (pwdlength >4 && pwdlength <15 {flag++} // password is 5-14 chars in length
    if (flag == 4) { // all four conditions met so OK ......................
    alert ("Your password passes!);
    return true;
    }
    alert ("Invalid password - try again!");
    password.focus();
    return false;
    }

    <form>
    <input type="password" size="15" maxlength="14" name="UserPwd" onchange="testpassword(this)">
    </form>

    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.

    Comment

    Working...
    X