1,105,229 Community Members

Javascript Validation - Password containing user data

Member Avatar
4Dante
Newbie Poster
9 posts since Feb 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi,

I've looked online for a few days but haven't been able to find an adequate solution.

I'm just trying to use javascript to validate that a password doesn't contain user data (first name, last name, etc...)

I really thought it would be simple. Here is what I'm using:

function validate_fname(field,alerttxt)
{
with (field)
{
re = /form.firstName.value/;
if(re.test(value))
  {alert(alerttxt);return false}
else {return true}
}
}

function validate_form(thisform)
{
with (thisform)
{
if (validate_fname(password,'Password must not contain users first name')==false)
{password.focus();return false} 
}
}

All the other validation I have on the page works (length, special chars, lower & upper case) but I can't seem to get it to check if the password contains their first name.

I have seen many pages that mention this being a good practice, but not how to implement it. I have been stuck on this one for weeks and I'm just clueless what else to do.

Thanks for any help you can provide.
Danny

Member Avatar
GliderPilot
Posting Whiz in Training
295 posts since Sep 2006
Reputation Points: 31 [?]
Q&As Helped to Solve: 48 [?]
Skill Endorsements: 14 [?]
 
0
 

Try this:

var re = form.firstName.value;
if(re.indexOf(value) !== -1) 
 {alert(alerttxt);return false}
else {return true}
Member Avatar
4Dante
Newbie Poster
9 posts since Feb 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi, thanks for your response.

I tried using exactly what you posted, but it didn't seem to work. I tried putting the users first name in the password (6Clark$6) but it allowed it.

Any other suggestions?

Thanks again.

Member Avatar
GliderPilot
Posting Whiz in Training
295 posts since Sep 2006
Reputation Points: 31 [?]
Q&As Helped to Solve: 48 [?]
Skill Endorsements: 14 [?]
 
0
 

What happens when you alert(form.firstName.value); ?

Member Avatar
4Dante
Newbie Poster
9 posts since Feb 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I get a pop up message saying "Clark".

Member Avatar
4Dante
Newbie Poster
9 posts since Feb 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

I also played around with changing the -1 value to 1, but it didn't allow any passwords to go through, regardless of them containing the word Clark or not, but that seems to be a property of the indexOf so I suppose it's working as it should.

I'm really at a loss, and afraid I'm just missing some minor detail or perhaps making this harder than I should be?

Member Avatar
GliderPilot
Posting Whiz in Training
295 posts since Sep 2006
Reputation Points: 31 [?]
Q&As Helped to Solve: 48 [?]
Skill Endorsements: 14 [?]
 
1
 

I'm sorry I wrote it in backwards should be this:

if(value.indexOf(re) !== -1)

Member Avatar
4Dante
Newbie Poster
9 posts since Feb 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Thank you, Thank you, Thank you, THANK YOU!!!!

That did it! It works!

Thank you again! I truly appreciate your help!

Member Avatar
4Dante
Newbie Poster
9 posts since Feb 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

One last thing....This isn't a requirement for my project, but I am curious...

If I wanted to make sure they didn't include any user data, regardless of it being in lowercase or uppercase, should I convert form.fname.value to uppercase then test it, and then convert it to lowercase and test it?

Question Answered as of 1 Year Ago by GliderPilot
Member Avatar
GliderPilot
Posting Whiz in Training
295 posts since Sep 2006
Reputation Points: 31 [?]
Q&As Helped to Solve: 48 [?]
Skill Endorsements: 14 [?]
 
0
 

I would convert both the password and userdata to lower case than test it.

Member Avatar
4Dante
Newbie Poster
9 posts since Feb 2008
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Perfect. Thanks again!

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article