equal
deleted
inserted
replaced
1 function passwordStrength(f,i,d){var k=1,h=2,b=3,a=4,c=5,g=0,j,e;if((f!=d)&&d.length>0){return c}if(f.length<4){return k}if(f.toLowerCase()==i.toLowerCase()){return h}if(f.match(/[0-9]/)){g+=10}if(f.match(/[a-z]/)){g+=26}if(f.match(/[A-Z]/)){g+=26}if(f.match(/[^a-zA-Z0-9]/)){g+=31}j=Math.log(Math.pow(g,f.length));e=j/Math.LN2;if(e<40){return h}if(e<56){return b}return a}; |
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 } |