2009-01-02 10:08:58 -05:00
|
|
|
// Password strength meter
|
2010-03-31 04:45:51 -04:00
|
|
|
function passwordStrength(password1, username, password2) {
|
|
|
|
var shortPass = 1, badPass = 2, goodPass = 3, strongPass = 4, mismatch = 5, symbolSize = 0, natLog, score;
|
|
|
|
|
|
|
|
// password 1 != password 2
|
|
|
|
if ( (password1 != password2) && password2.length > 0)
|
|
|
|
return mismatch
|
2009-01-02 10:08:58 -05:00
|
|
|
|
|
|
|
//password < 4
|
2010-03-31 04:45:51 -04:00
|
|
|
if ( password1.length < 4 )
|
|
|
|
return shortPass
|
2009-01-02 10:08:58 -05:00
|
|
|
|
2010-03-31 04:45:51 -04:00
|
|
|
//password1 == username
|
|
|
|
if ( password1.toLowerCase() == username.toLowerCase() )
|
|
|
|
return badPass;
|
2009-01-02 10:08:58 -05:00
|
|
|
|
2010-03-31 04:45:51 -04:00
|
|
|
if ( password1.match(/[0-9]/) )
|
|
|
|
symbolSize +=10;
|
|
|
|
if ( password1.match(/[a-z]/) )
|
|
|
|
symbolSize +=26;
|
|
|
|
if ( password1.match(/[A-Z]/) )
|
|
|
|
symbolSize +=26;
|
|
|
|
if ( password1.match(/[^a-zA-Z0-9]/) )
|
|
|
|
symbolSize +=31;
|
2009-01-02 10:08:58 -05:00
|
|
|
|
2010-03-31 04:45:51 -04:00
|
|
|
natLog = Math.log( Math.pow(symbolSize, password1.length) );
|
2009-01-02 10:08:58 -05:00
|
|
|
score = natLog / Math.LN2;
|
2010-03-31 04:45:51 -04:00
|
|
|
|
|
|
|
if (score < 40 )
|
|
|
|
return badPass
|
|
|
|
|
|
|
|
if (score < 56 )
|
|
|
|
return goodPass
|
|
|
|
|
2009-01-02 10:08:58 -05:00
|
|
|
return strongPass;
|
|
|
|
}
|