Password Strength Meter API Documentation
- Benjamin Kuker
- March 22, 2011
Password Srength Meter is a JavaScript password strength checker based on MooTools 1.3. It aims to provide simple, reliable password strength indications across all browsers in an unobtrusive manner. It is 100% styled by CSS and allows for custom validations. It can be used with effects or without and has an optional text component that changes with each change of state. The text defaults to 'Poor', 'Weak', 'Medium', and 'Strong'; but it can be changed according to preference or language.
Documentation
Class: PassMeter
This class is for evaluating the strength of a password by using a CSS-styled visual meter and/or text.
Implements:
Notes:
- If you are using a single CSS sprite as background images for your password meter, it's recommended to turn the effects off as the resulting animation may not be what you desire. If you still wish to keep the animation, the only alternative option is to use multiple images.
PassMeter Method: constructor
Password Strength Meter is completely unobtrusive and requires no changes to existing markup.
Syntax:
var password = new PassMeter(passwordFieldName[, options]);
Arguments:
- passwordFieldName - (string) The name of the password form element on which validation should be performed.
- options - (object, optional) Any of the options below.
Options:
- injectAfter - (string, defaults to null) The name of the form element after which the password meter should be injected.
- minLength - (integer, defaults to 6) The minimum length of the password.
- maxLength - (integer, defaults to 15) The maximum length of the password.
- useFx - (boolean, defaults to true) If the animation effects should be used.
- transition - (function, defaults to Fx.Transitions.Sine.easeOut) The type of transition to be used in the animation. Uses Fx.Transitions.
- duration - (integer, defaults to 250) The duration of the animation transition in milliseconds.
- containerId - (string, defaults to 'containerId') The id of the containing element for the password meter.
- meterId - (string, defaults to 'meterId') The id of the containing element for the password meter.
- poorClass - (string, defaults to 'poorPass') The class for a poor password element.
- weakClass - (string, defaults to 'weakPass') The class for a weak password element.
- mediumClass - (string, defaults to 'mediumPass') The class for a medium password element.
- strongClass - (string, defaults to 'strongPass') The class for a strong password element.
- textId - (string, defaults to 'textId') The id of the containing element for the text status message.
- useText - (boolean, defaults to true) If the text password status messages should be used.
- poorText - (string, defaults to 'Poor') The text to be used for a poor password element.
- weakText - (string, defaults to 'Weak') The text to be used for a weak password element.
- mediumText - (string, defaults to 'Medium') The text to be used for a medium password element.
- strongText - (string, defaults to 'Strong') The text to be used for a strong password element.
- weakRegEx - (string, defaults to '([a-z]{1}[A-Z]{1})|([A-Z]{1}[a-z]{1})[^\s]') The regular expression to be used for a weak password element. The default weak regex tests that at least one uppercase and one lowercase letter has been used.
- mediumRegEx - (string, defaults to '[0-9]{1}') The regular expression to be used for a medium password element. The default medium regex tests that at least one number has been used.
- strongRegEx - (string, defaults to '[^a-zA-Z0-9]{1}') The regular expression to be used for a strong password element. The default strong regex tests that at least one special (non-alphanumeric) character has been used.
Example:
window.addEvent('domready', function(){
var password = new PassMeter('password', {
poorText: 'Stinky',
weakText: 'Wimpy',
mediumText: 'Mediocre',
strongText: 'Superman'
poorClass: 'stinky',
weakClass: 'wimpy',
mediumClass: 'mediocre',
strongClass: 'superman'
});
});
Further JavaScript Regular Expression Resources:
- http://www.regular-expressions.info/javascript.html - Specifics of writing regular expressions for JavaScript.
- http://regexlib.com/ - A regular expression library. Be sure to check out their cheat sheet.
Tags
Your Comments Are Valuable - Join The Discussion!
Find what you need.
Here's the latest for developers.
Popular programming tutorials.
We're on the web.
We are where you are. Discover great content by becoming our fan on Facebook, following us on Twitter, or subscribing to our RSS feeds.
Help us spread the word.