I wrote this verification method, but I have problems with it.
function validate_password(pwd)
{
var score = 0;
if (pwd.length<8)
return false;
if (/[a-z]/g.test(pwd))
{
console.log('a-z test on "'+pwd+'":' + /[a-z]+/g.test(pwd));
score++;
}
if (/[A-Z]/g.test(pwd))
{
console.log('A-Z test on: "'+pwd+'":' + /[A-Z]+/g.test(pwd));
score++;
}
if (/\d/g.test(pwd))
{
console.log('digit test on: "'+pwd+'":' + /\d/g.test(pwd));
score++;
}
if (/\W/g.test(pwd))
{
console.log('spec char test on: "'+pwd+'":' + /\W/g.test(pwd));
score++;
}
if (score>=3)
return true;
else
return false;
}
This is what is written on the console:
>>> validate_password('aaasdfF#3s')
a-z test on "aaasdfF#3s":true
A-Z test on: "aaasdfF#3s":true
digit test on: "aaasdfF#3s":true
spec char test on: "aaasdfF#3s":true
true
>>> validate_password('aaasdfF#3s')
a-z test on "aaasdfF#3s":true
false
On the first try, it seems to work as expected, but when I call this method a second time, it does not work as expected.
So my question is: why are there differences between the results of the first attempt and the second attempt?
Thank!:)
user290043
source
share