2007-12-19 17:40:44 -05:00
|
|
|
// Password strength meter
|
|
|
|
|
2008-03-14 16:17:17 -04:00
|
|
|
function passwordStrength(password,username) {
|
2008-10-22 00:20:50 -04:00
|
|
|
var shortPass = 1, badPass = 2, goodPass = 3, strongPass = 4;
|
2008-03-02 15:17:30 -05:00
|
|
|
|
2008-10-22 00:20:50 -04:00
|
|
|
//password < 4
|
2008-08-24 10:35:46 -04:00
|
|
|
if (password.length < 4 ) { return shortPass };
|
2008-03-02 15:17:30 -05:00
|
|
|
|
2007-12-19 17:40:44 -05:00
|
|
|
//password == username
|
2008-08-24 10:35:46 -04:00
|
|
|
if (password.toLowerCase()==username.toLowerCase()) return badPass;
|
2008-03-02 15:17:30 -05:00
|
|
|
|
2008-10-22 00:20:50 -04:00
|
|
|
var symbolSize = 0;
|
|
|
|
if (password.match(/[0-9]/)) symbolSize +=10;
|
|
|
|
if (password.match(/[a-z]/)) symbolSize +=26;
|
2008-12-09 13:03:31 -05:00
|
|
|
if (password.match(/[A-Z]/)) symbolSize +=26;
|
2008-10-22 00:20:50 -04:00
|
|
|
if (password.match(/[^a-zA-Z0-9]/)) symbolSize +=31;
|
2008-12-09 13:03:31 -05:00
|
|
|
|
2008-10-22 00:20:50 -04:00
|
|
|
var natLog = Math.log( Math.pow(symbolSize,password.length) );
|
|
|
|
var score = natLog / Math.LN2;
|
|
|
|
if (score < 40 ) return badPass
|
|
|
|
if (score < 56 ) return goodPass
|
2008-08-24 10:35:46 -04:00
|
|
|
return strongPass;
|
2008-10-22 00:20:50 -04:00
|
|
|
}
|