mirror of
https://github.com/WordPress/WordPress.git
synced 2024-12-23 17:48:01 +01:00
a750885c8e
git-svn-id: http://svn.automattic.com/wordpress/trunk@10291 1a063a9b-81f0-0310-95a4-ce76da25c4cd
22 lines
719 B
JavaScript
22 lines
719 B
JavaScript
// Password strength meter
|
|
function passwordStrength(password,username) {
|
|
var shortPass = 1, badPass = 2, goodPass = 3, strongPass = 4, symbolSize = 0, natLog, score;
|
|
|
|
//password < 4
|
|
if (password.length < 4 ) { return shortPass };
|
|
|
|
//password == username
|
|
if (password.toLowerCase()==username.toLowerCase()) return badPass;
|
|
|
|
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;
|
|
|
|
natLog = Math.log( Math.pow(symbolSize,password.length) );
|
|
score = natLog / Math.LN2;
|
|
if (score < 40 ) return badPass
|
|
if (score < 56 ) return goodPass
|
|
return strongPass;
|
|
}
|