...

View Full Version : password validation



ugly
08-19-2004, 10:25 PM
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.

Willy Duitt
08-19-2004, 10:54 PM
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 (http://www.codingforums.com/search.php?) 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

Philip M
08-20-2004, 07:47 AM
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'?)

Willy Duitt
08-20-2004, 01:04 PM
Yea nothing like ignoring an active thread (http://www.codingforums.com/showthread.php?t=42747) 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..... :eek:

.....Willy

ugly
08-20-2004, 05:03 PM
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;
}
}

Willy Duitt
08-20-2004, 05:13 PM
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

ugly
08-20-2004, 05:38 PM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum