jQuery Password Strength Meter

By Tane Piper (aka digitalspaghetti).

This is a very simple plugin that provides password strength functionality for your signup forms. To activate the plugin, create a password field in your form and attach the function to it.

<input type="password" id="password" name="password" />
<script type="text/javascript">
	jQuery('#password').pstrength();
</script>
		

Now you have a fully functional password strength meter. The plugin defines some options and methods that allow you to customise your form. You can override the default settings, switch on or off certain validation critera, and even write your own validation methods.

Below are a list of options you can overide:

'defaults' : {
	'displayMinChar': true,
	'minChar': 8,
	'minCharText': 'You must enter a minimum of %d characters',
	'colors': ["#f00", "#c06", "#f60", "#3c0", "#3f0"],
	'scores': [20, 30, 43, 50],
	'verdicts':	['Weak', 'Normal', 'Medium', 'Strong', 'Very Strong'],
	'raisePower': 1.4
},
'ruleScores' : {
	'length': 0,
	'lowercase': 1,
	'uppercase': 3,
	'one_number': 3,
	'three_numbers': 5,
	'one_special_char': 3,
	'two_special_char': 5,
	'upper_lower_combo': 2,
	'letter_number_combo': 2,
	'letter_number_char_combo': 2
},
	'rules' : {
	'length': true,
	'lowercase': true,
	'uppercase': true,
	'one_number': true,
	'three_numbers': true,
	'one_special_char': true,
	'two_special_char': true,
	'upper_lower_combo': true,
	'letter_number_combo': true,
	'letter_number_char_combo': true
}			
		

To overide the defaults, you simply need to pass these into the initialization function.

jQuery('#password').pstrength({minChar: 12});
		

To add your own custom validation rules, you can use the jQuery().pstrength.addRule method.

jQuery('#password').pstrength.addRule('twelvechar', function (word, score) {
  return word.length >= 12 && score;
}, 3, true);
		

This will add a lamda function that returns the score if the length of the password is greater or equal to 12 characters. The first parameter is the name of the validation rule. The second is the function to execute. Each function must be passed the word and score in that order. The third rule is the score to return if the validation is true. The forth parameter makes sure the validation rule is active. If false is passed your validation rule will be added but ignored.

You can also overide the scores of each rules, and wether to bypass any rules by setting them to false. To do this, two simple methods are provided:

jQuery('#password').pstrength.changeScore('one_number', 50);
jQuery('#password').pstrength.ruleActive('one_number', false);
		
Dependancies:

Demo