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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    validating password

    i am trying to validate password. my requirement is it should not contain morethan 4 letters of username and it should contain alphabets(small and big) numbers and special characters.everything is working except 4 letters of their username.if they enter more than 4 letters it's giving alert and submitting the form and if username have multiple same letters it's not working. here is my code. i appreciate if any help

    function goAddChange()
    {
    var form1=window.document.frmLogIn

    if(form1.txtUserID.value == null || form1.txtUserID.value.length == 0)
    {
    alert('Please Enter User Name.');
    form1.txtUserID.focus();
    return false;
    }
    if(form1.txtPWD.value == null || form1.txtPWD.value.length == 0 )
    {
    alert('Please Enter Password.');
    form1.txtPWD.focus();
    return false;
    }
    if(form1.txtNewPWD.value == null || form1.txtNewPWD.value.length == 0 )
    {
    alert('Please Enter New Password.');
    form1.txtNewPWD.focus();
    return false;
    }
    if(form1.txtNewPWD.value.length < 8 )
    {
    alert('New Password Should Be Eight Characters.');
    form1.txtNewPWD.focus();
    return false;
    }
    if(window.document.frmLogIn.txtRNewPWD.value !=window.document.frmLogIn.txtNewPWD.value)
    {
    alert('New password and Retype New Password are not same')
    form1.txtRNewPWD.focus();
    return false;
    }

    //password validation
    var counter=0;
    for (var i = 0 ; i < form1.txtUserID.value.length ; i++)
    {
    var character = form1.txtUserID.value.charAt(i);
    if(form1.txtNewPWD.value.indexOf(character) > -1)
    {
    counter++;
    }
    }
    if(counter > 4)
    {
    alert("New Password Must Not Contain All Or Part Of User Name!");
    form1.textNewPWD.value='';
    form1.txtNewPWD.focus();
    return false;
    }//End password validation

    var upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    var lower = "abcdefghijklmnopqrstuvwxyz";
    var numbers = "0123456789";
    var special = "!@#$%^*/&?";
    if (form1.txtUserID.value.indexOf(form1.txtNewPWD.value) == -1)
    {
    var a = 0;
    var b = 0;
    var c = 0;
    var d = 0;
    for (var i = 0 ; i < form1.txtNewPWD.value.length ; i++)
    {
    //alert(form1.password.value.charAt(i));
    if (upper.indexOf(form1.txtNewPWD.value.charAt(i)) > -1)
    {
    a = 1;
    }
    else if (lower.indexOf(form1.txtNewPWD.value.charAt(i)) > -1)
    {
    b = 1;
    }
    else if (numbers.indexOf(form1.txtNewPWD.value.charAt(i)) > -1)
    {
    c = 1;
    }
    else if (special.indexOf(form1.txtNewPWD.value.charAt(i)) > -1)
    {
    d = 1;
    }
    }
    if((a+b+c+d) < 3)
    {
    alert('Password must contain atleast 3 of the following 4
    categories.\n English uppercase characters (A through Z). \n English
    lowercase characters (a through z). \n Base 10 digits (0 through 9). \n
    Non-alphanumeric characters (e.g., !, $, #, %).');
    form1.txtNewPWD.focus();
    return false;
    }
    else
    {
    //alert('Valid Password.');
    return true;
    }
    }
    else
    {
    //alert('Incorrect Password, Must not contain all or part of your user aaaccount name.');
    //form1.txtPassword.focus();
    return false;

    }
    }

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,174
    Thanks
    203
    Thanked 2,549 Times in 2,527 Posts
    This has been requested before, so I have the idea it is a homework
    assignment.

    Hint:- search this forum for posts by ugly

  • #3
    New to the CF scene
    Join Date
    Jan 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if you know can you please post code. ugly's requirement is different compare to mine. i tried with his code. it didn't work.

  • #4
    New Coder
    Join Date
    Jan 2004
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    still need help validating password

    can anyone give me idea or solution to fix my problem.

    thanks.


  •  

    Posting Permissions

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