jQuery password strength checker

The best way is to take an existing plugin as TJB suggested.

As to your question about the code itself, a nicer way is to write it like that:

var pass = "f00Bar!";

var strength = 1;
var arr = [/.{5,}/, /[a-z]+/, /[0-9]+/, /[A-Z]+/];
jQuery.map(arr, function(regexp) {
  if(pass.match(regexp))
     strength++;
});

(Modified to correct syntax errors.)


On top of gs' answer, you should check the password against common dictionary words (using a hash, probably). Otherwise a weak password like 'Yellow1' will be evaluated as strong by your logic.


I would suggest evaluating an existing jQuery password strength plugin. (unless your just doing it as an exercise)

Here are a few links I found:

http://www.visual-blast.com/javascript/password-strength-checker/

http://phiras.wordpress.com/2007/04/08/password-strength-meter-a-jquery-plugin/