2007-12-19 23:40:44 +01:00
|
|
|
// Password strength meter
|
|
|
|
|
2008-03-14 21:17:17 +01:00
|
|
|
function passwordStrength(password,username) {
|
2008-10-22 06:20:50 +02:00
|
|
|
var shortPass = 1, badPass = 2, goodPass = 3, strongPass = 4;
|
2008-03-02 21:17:30 +01:00
|
|
|
|
2008-10-22 06:20:50 +02:00
|
|
|
//password < 4
|
2008-08-24 16:35:46 +02:00
|
|
|
if (password.length < 4 ) { return shortPass };
|
2008-03-02 21:17:30 +01:00
|
|
|
|
2007-12-19 23:40:44 +01:00
|
|
|
//password == username
|
2008-08-24 16:35:46 +02:00
|
|
|
if (password.toLowerCase()==username.toLowerCase()) return badPass;
|
2008-03-02 21:17:30 +01:00
|
|
|
|
2008-10-22 06:20:50 +02:00
|
|
|
var symbolSize = 0;
|
|
|
|
if (password.match(/[0-9]/)) symbolSize +=10;
|
|
|
|
if (password.match(/[a-z]/)) symbolSize +=26;
|
|
|
|
if (password.match(/[A-Z]/)) symbolSize +=26;
|
|
|
|
if (password.match(/[^a-zA-Z0-9]/)) symbolSize +=31;
|
|
|
|
|
|
|
|
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 16:35:46 +02:00
|
|
|
return strongPass;
|
2008-10-22 06:20:50 +02:00
|
|
|
}
|