0

I am working with passwords now and want to make user to create complicated password. I use jQuery to check if password is long enough and how strong it is depending on used characters. Still, cant figure out how to make user to create password with no duplicated chars, so he cant make password like '111111111111111111111111' or '1qAz1qAz1qAz' etc. My code is here:

$("#new_pass").keyup(function() {
    var newpass = $(this).val();
    var chars = 0;
    if((/[a-z]/).test(newpass)) chars +=  26;
    if((/[A-Z]/).test(newpass)) chars +=  26;
    if((/[0-9]/).test(newpass)) chars +=  10;
    if((/[^a-zA-Z0-9]/).test(newpass)) chars +=  32; 
    var strength = Math.pow(chars, newpass.length)
        alert(strength)
}

Thanks in advance.

4

1 に答える 1

2

Perhaps you could use something simple like this:

 /(\w+)(?=\1)/g

It matches one or more word characters then checks to see if they are followed by that exact string.

Basic test (in Coffeescript)

 pattern = /(\w+)(?=\1)/g
 console.log pattern.test("1qAz1qAz1qAz")
 console.log pattern.test("111111111111111")
 console.log pattern.test("abcdefg")         
 console.log pattern.test("abccdefg")

Outputs:

 true
 true
 false
 true

As a side note, upper and lower case does matter, so for instance:

 pattern.test("abcCdefg")

Would in fact return false.

于 2012-04-28T23:02:50.040 に答える