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 7 of 7
  1. #1
    New Coder
    Join Date
    Jan 2004
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    password validation

    Hi

    I want to validate password, it should contain 8 characters and upto 4 characters of their username remaining numbers or special characters. i would appreciate if any help
    thanks.

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by ugly
    Hi

    I want to validate password, it should contain 8 characters and upto 4 characters of their username remaining numbers or special characters. i would appreciate if any help
    thanks.
    Try the forums Search Feature.... this is an often asked and often answered question.... and you should have no problem finding numerous examples of how this is done...

    .....Willy

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,303
    Thanks
    203
    Thanked 2,562 Times in 2,540 Posts

    Question

    Try the forums Search Feature.... this is an often asked and often answered question.... and you should have no problem finding numerous examples of how this is done...

    .....Willy

    In fact ugly has asked exactly this same question twice before

    http://www.codingforums.com/showthread.php?t=40797
    http://www.codingforums.com/showthread.php?t=42747

    and been given helpful answers by Willy (and others).

    I now see that the question is not exactly the same. Previously the password had to contain no characters which are in the user name. Now it MUST contain up to four. (is zero 'up to four'?)
    Last edited by Philip M; 08-20-2004 at 08:50 AM.

  • #4
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yea nothing like ignoring an active thread which relative example code was recently provided to the O/P and which only a small modification to a regular expression would be required in favor of starting an entirely new thread regarding essentially the same question and then not providing any code to work with.....

    .....Willy
    Last edited by Willy Duitt; 08-20-2004 at 02:06 PM.

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

    Code

    Hi

    I tried to work with last posted code but it's not working for me.it's taking only first 4 letters of user name .if i give saly(henrysakl) of username it's not accepting.i am sorry for opening new thread to everybody.i didn't know that.

    Here is my code

    if(form1.txtPWD.value.length < 8 )
    {
    alert('Password Should Be Eight Characters.');
    form1.txtPWD.focus();
    return false;
    }
    //passvalidation
    var badChar = form1.txtUserID.value;
    for (var i=4;i<badChar.length;i++)
    {
    var illChar = badChar.charAt(i);
    if (form1.txtPWD.value.indexOf(illChar,0) != -1)
    {
    alert("Password Must Not Contain All Or Part Of User Name!");
    form1.txtPWD.value='';
    form1.txtPWD.focus();
    return false;
    }
    }

  • #6
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by ugly
    Hi

    I tried to work with last posted code but it's not working for me.it's taking only first 4 letters of user name .if i give saly(henrysakl) of username it's not accepting.i am sorry for opening new thread to everybody.i didn't know that.

    Here is my code

    if(form1.txtPWD.value.length < 8 )
    {
    alert('Password Should Be Eight Characters.');
    form1.txtPWD.focus();
    return false;
    }
    //passvalidation
    var badChar = form1.txtUserID.value;
    for (var i=4;i<badChar.length;i++)
    {
    var illChar = badChar.charAt(i);
    if (form1.txtPWD.value.indexOf(illChar,0) != -1)
    {
    alert("Password Must Not Contain All Or Part Of User Name!");
    form1.txtPWD.value='';
    form1.txtPWD.focus();
    return false;
    }
    }

    It's not working for you because you never mentioned that you would be including braces ( ) within the username and that is breaking the regular expression which was not written for that eventuality.....

    if(!form.newPass1.value.match(/[a-z]{8,}/i)){

    ......Willy

    Edit: Actually, the problem with including braces probably lies here: if(form.newPass1.value.match(chars[j])){
    Which would not be hard to fix but it appears you went a totally different route....

    Good luck;
    .....Willy
    Last edited by Willy Duitt; 08-20-2004 at 06:21 PM.

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

    modified code

    i modified code now it's accepting four characters of user name but i got another problem if i give my username reverse in password field it's taking entire username.Example username:henryjkl if igve pwd like "lkjyrneh" it's taking entire thing. if i give pwd like "hryjk" it's giving error this is right b'coz i want to accept only four characters of username . if igive ryjk it's not giving error this is also right but problem is if igive username in reverse order it's taking.

    here is my code

    if(form1.txtPassword.value.length < 8 )
    {
    alert('Password Should Be Eight Characters.');
    form1.txtPassword.value='';
    form1.txtPassword.focus();
    return false;
    }
    //passvalidation
    var badChar = form1.txtUsername.value;
    for (var i=4;i<badChar.length;i++)
    {

    var illChar = badChar.charAt(i);

    if (form1.txtPassword.value.indexOf(illChar,4) != -1)
    {
    alert("Password Must Not Contain All Or Part Of User Name!");
    //form1.txtPassword.value='';
    return false;
    }

    }

    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
    •