equal
deleted
inserted
replaced
1 // Password strength meter |
|
2 function passwordStrength(password1, username, password2) { |
|
3 var shortPass = 1, badPass = 2, goodPass = 3, strongPass = 4, mismatch = 5, symbolSize = 0, natLog, score; |
|
4 |
|
5 // password 1 != password 2 |
|
6 if ( (password1 != password2) && password2.length > 0) |
|
7 return mismatch |
|
8 |
|
9 //password < 4 |
|
10 if ( password1.length < 4 ) |
|
11 return shortPass |
|
12 |
|
13 //password1 == username |
|
14 if ( password1.toLowerCase() == username.toLowerCase() ) |
|
15 return badPass; |
|
16 |
|
17 if ( password1.match(/[0-9]/) ) |
|
18 symbolSize +=10; |
|
19 if ( password1.match(/[a-z]/) ) |
|
20 symbolSize +=26; |
|
21 if ( password1.match(/[A-Z]/) ) |
|
22 symbolSize +=26; |
|
23 if ( password1.match(/[^a-zA-Z0-9]/) ) |
|
24 symbolSize +=31; |
|
25 |
|
26 natLog = Math.log( Math.pow(symbolSize, password1.length) ); |
|
27 score = natLog / Math.LN2; |
|
28 |
|
29 if (score < 40 ) |
|
30 return badPass |
|
31 |
|
32 if (score < 56 ) |
|
33 return goodPass |
|
34 |
|
35 return strongPass; |
|
36 } |
|