Combine jQuery and zxcvbn to create a password strength meter.
As of 0.5.0, the wrapper will be automatically added beneath the target input field
Add jquery
(tested with 1.10.0), jquery.strengthify.js
and
strengthify.css
to your document.
If using the message option, include bootstrap.
If using the titles option, include bootstrap's tooltip.js
,
<script src="jquery-1.10.0.min.js"></script>
<script src="tooltip.js"></script>
<script src="jquery.strengthify.js"></script>
<link rel="stylesheet" href="bootstrap.min.css" type="text/css">
<link rel="stylesheet" href="strengthify.css" type="text/css">
Because zxcvbn is really
heavyweight, it will be loaded asynchronously from zxcvbn/zxcvbn.js
.
This can however be configured with an optional parameter.
Then call .strengthify
on the password input field.
$('#password-field').strengthify()
That's it. Now the password strength meter will be updated after each keystroke.
The path and the title of the different strength categories can
be configured with the first parameter of .strengthify
.
- drawTitles
- pop-up text (above)
- drawMessage
- detailed message beneath input
- drawBars
- password strength color progression bars beneath input
- $addAfter
- element after which the strengthify element should be inserted
- nonce
- a nonce that is added to the `<script>` tag to load the zxcvbn.js file asynchronously
Default:
{
"zxcvbn": "zxcvbn/zxcvbn.js",
"titles": [
"Weakest",
"Weak",
"So-so",
"Good",
"Perfect"
],
"drawTitles": false,
"drawMessage": false,
"drawBars": true,
"$addAfter": null
}
Overwrite example:
$('#password-field').strengthify({zxcvbn: 'my/path/to/zxcvbn.js'})
Use 'onResult' callback option like:
$('#password-field').strengthify({
zxcvbn: 'my/path/to/zxcvbn.js',
onResult: function(result) {
var submitBtn = $('input[type=submit]');
if (result.score < 3) {
submitBtn.prop('disabled', 'disabled');
} else {
submitBtn.prop('disabled', false);
}
}
})
- 0.5.6
-
- set the nonce properly in all browsers (#24)
- 0.5.5
-
- allow to specify a nonce for the loaded script (#23)
- 0.5.4
-
- do not use `eval()` anymore (#19)
- 0.5.3
-
- make possible to specify the element to add the strength bar after (#20)
- provide minified version (#16)
- 0.5.2
-
- use eval directly (#14)
- added missing break (#13)
- 0.5.1
- add tilesOptions (#10) - you can choose now between tooltip and element or both - thanks to @feirer
- 0.5.0
- fairly substantial changes:
- added feedback message
- $.each(...) functionality
- restructuring wrapping
- feature flags
- 0.4.1
- hotfix for missing ;
- 0.4
- syntax and performance cleanups
- 0.3
- some fixes:
- migrate from "display" to "opacity"
- fix pasting to input field
- add tipsy with strength
- 0.2
- solve mimetype issues
- 0.1
- Initial version