passy is a jQuery plugin to rate and generate passwords.
var $input = $( '#input' ); var $output = $( '#output' ); $.passy.requirements.length.min = 4; var feedback = [ { color: '#c00', text: 'poor' }, { color: '#c80', text: 'okay' }, { color: '#0c0', text: 'good' }, { color: '#0c0', text: 'fabulous!' } ]; $input.passy(function(strength, valid) { $output.text(feedback[strength].text); $output.css('background-color', feedback[strength].color); if( valid ) $input.css(' border-color', 'green' ); else $input.css( 'border-color', 'red' ); }); $('#generate').click(function() { $input.passy( 'generate', 8 ); });
$( field ).passy(function( strength, valid ) { // Do stuff }); $( field ).passy( 'generate', length );
Property | Default | Description |
$.passy.patterns |
[ '0123456789', 'abcdefghijklmnopqrstuvwxyz', 'qwertyuiopasdfghjklzxcvbnm', 'azertyuiopqsdfghjklmwxcvbn', '!#$*+-.:?@^' ] |
A list of patterns passwords should avoid (case insensitive) |
$.passy.threshold |
{ medium: 16, high: 22, extreme: 36 } |
The minimum scores requires to be categorized |
$.passy.requirements |
{ characters: passy.character.DIGIT | passy.character.LOWERCASE | passy.character.UPPERCASE, length: { min: 6, max: Infinity } } |
The requirements which makes a password valid |
$.passy.dictionary | [] |
A collection of words passwords should avoid (case insensitive) |
Just in case you need 'em, I made utility functions!
Method | Returns | Description |
$.passy.analize( password ) |
Password strength (see Constants) |
Get the quality of a password |
$.passy.analizeCharacter( character ) | 1-5 | Get the quality of a single character |
$.passy.analizePatterns( password ) | < 0 | Get the score based on pattern matching |
$.passy.analizePattern( password, pattern ) | > 0 | Get the quality of a password based on one pattern |
$.passy.analizeScore( score ) |
Password strength (see Constants) |
Turns a score to a password result |
$.passy.contains( string, chartype ) |
true / false
|
Checks if the string contains a chartype (see Constants) |
$.passy.generate( length ) | A password | Generate a password |
$.passy.valid( string ) |
true / false
|
Checks if a string is a valid password based on $.passy.requirements |
Constant | Description |
$.passy.strength.LOW | Low quality password |
$.passy.strength.MEDIUM | Medium quality password |
$.passy.strength.HIGH | High quality password |
$.passy.strength.EXTREME | Very high quality password |
Constant | Description |
$.passy.character.DIGIT | A digit character (used in $.passy.contains()) |
$.passy.character.LOWERCASE | A lowercase character (used in $.passy.contains()) |
$.passy.character.UPPERCASE | An uppercase character (used in $.passy.contains()) |
$.passy.character.PUNCTUATION | A punctuation character (used in $.passy.contains()) |