My JavaScript book is out! Don't miss the opportunity to upgrade your beginner or average dev skills.

Monday, June 18, 2007

FireFox 3 Password Manager? Well, check You password security :-)

This simple function returns a short number from 0 to 9, for a total of 10 points, to verify security level of your choosed password.

Score is evaluated in two different parts: one for the password length and one for character used for that password (different and alpha numeric, upper/lower case is better!).

This version is quite better than older one showed in this post: Unobtrusive Password Security Level Form

So have fun with password and take care your security :-)


function PasswordSecurityLevel(pass){
var level = 0,
length = pass.length,
re = PasswordSecurityLevel,
check = [re.all.test(pass), re.alu.test(pass), re.num.test(pass)],
i, chars, key;
switch(true){
case length > 15: level++;
case length > 11: level++;
case length > 7: level++;
case length > 5: level++;
break;
};
if(re.oth.test(pass))
level++;
if(check[0] && check[1] && check[2])
level++;
if((check[0] && check[1]) || (check[0] && check[2]) || (check[1] && check[2]))
level++;
if(level > 5) {
for(i = 0, chars = {}; i < length; i++)
chars[pass.charCodeAt(i).toString()] = true;
i = 0;
for(key in chars)
i += chars.hasOwnProperty(key) ? 1 : 0;
switch(true){
case i > 9: level++;
case i > 7: level++;
break;
};
};
return level;
};
PasswordSecurityLevel.num = /[0-9]/;
PasswordSecurityLevel.all = /[a-z]/;
PasswordSecurityLevel.alu = /[A-Z]/;
PasswordSecurityLevel.oth = /[^a-zA-Z0-9]/;

No comments: