Blame | Letzte Änderung | Log anzeigen | RSS feed
# jQuery Password Strength Meter for Twitter Bootstrap[](https://travis-ci.org/ablanco/jquery.pwstrength.bootstrap)[](https://codeclimate.com/github/ablanco/jquery.pwstrength.bootstrap)[](https://david-dm.org/ablanco/jquery.pwstrength.bootstrap#info=devDependencies)The jQuery Password Strength Meter is a plugin for Twitter Bootstrap thatprovides rulesets for visualy displaying the quality of a users typed inpassword.Dual licensed under the MIT and GPL licenses. You can choose the one thatsuits your purposes better.[npm entry](https://www.npmjs.com/package/pwstrength-bootstrap)## Requirements* jQuery 1.7 or higher* Bootstrap 2, 3 or 4### Not using Bootstrap?This plugin currently relies heavily on Bootstrap and it is not possible touse it with another framework without making big changes in the code orforgetting completely about the UI feedback.Forks to use it with another frameworks that I know of:* [Zurb Foundation fork by edtownend](https://github.com/edtownend/jquery.pwstrength.foundation)## How to use itJust invoke the plugin on the password fields you want to attach a strengthmeter to. For example, to use it on all the password fields with the defaultexamples:```javascript$(':password').pwstrength();```To apply it only to one input and change the options:```javascript$('#passwd1').pwstrength({ui: { showVerdictsInsideProgressBar: true }});```## OptionsClick here to find [the complete list of options for the plugin](OPTIONS.md).## MethodsOnce the plugin has been initialized, it is possible to interact with itthrough the methods.### Force an updateIt is possible to force an update on a password strength meter. It will forcea new score calculation and an update of the UI elements, the `onKeyUp`callback will be called.```javascript$("#passwdfield").pwstrength("forceUpdate");```### Remove the strength meterThis will remove the data associated to the meter, and the UI elements.```javascript$("#passwdfield").pwstrength("destroy");```### Adding Custom RulesThe plugin comes with the functionality to easily define your own custom rules.The format is as follows:```javascript$("#passwdfield").pwstrength("addRule", "ruleName", function (options, word, score) {}, rule_score, rule_enabled);```Example:```javascript$("#passwdfield").pwstrength("addRule", "testRule", function (options, word, score) {return word.match(/[a-z].[0-9]/) && score;}, 10, true);```### Change the score associated to a ruleIt is possible to change the score given by a rule. It works like this:```javascript$("#passwdfield").pwstrength("changeScore", "wordSequences", -100);```That would penalize even more the presence of sequences in the password.### Activate and deactivate rulesIt is also possible to activate or deactivate rules. It as simple as:```javascript$("#passwdfield").pwstrength("ruleActive", "wordSequences", false);```That would avoid looking for sequences in the password being tested.## Callback FunctionsThe plugin provides two callback functions, onLoad and onKeyUp. You can usethem like this:```javascript$(document).ready(function () {var options = {};options.common = {onLoad: function () {$('#messages').text('Start typing password');},onKeyUp: function (evt, data) {$("#length-help-text").text("Current length: " + $(evt.target).val().length + " and score: " + data.score);}};$(':password').pwstrength(options);});```## Extra securityThe plugin comes with two validation rules deactivated by default. One checksfor too many character repetitions, and the other checks the number ofcharacter classes used. An easy way to increase the security of the passwordsis to activate this two rules:```javascript$(document).ready(function () {var options = {};options.rules = {activated: {wordTwoCharacterClasses: true,wordRepetitions: true}};$(':password').pwstrength(options);});```## ExamplesThere are some examples in the `examples` directory. Just serve them with anywebserver and check them in your browser. Make sure you serve the `examples`directory as the site root. For example:```bashcd examplespython -m SimpleHTTPServer```And go to [localhost:8000](http://localhost:8000).Alternatively, you can check-out the examples in a [hosted demo](https://cdn.rawgit.com/ablanco/jquery.pwstrength.bootstrap/master/examples/index.html).## Build and TestThe build and testing processes rely on [Grunt](http://gruntjs.com/). To usethem you need to have [node.js](http://nodejs.org/) and grunt-cli installed onyour system. Assuming you have node.js in your Linux system, you'll need to dosomething like this:```bashsudo npm install -g grunt-cli```Now you have the grunt command line utility installed globally.### Bundle and minifiedTo generate the bundle and the minified file you only need to execute this inthe project directory:```bashnpm install -dgrunt```It will check the source files, and build a minified version with itscorresponding source map. The generated files will be available in the `dist`directory.### TestingTo run the tests the only thing you need to do is execute this in the projectdirectory:```bashnpm install -dgrunt test```It will check all the source files with [JSLint](http://jslint.com) and run thetests, which are written with [Jasmine](http://jasmine.github.io/). You'll findthe tests source code in the `spec` directory.[Travis](https://travis-ci.org/ablanco/jquery.pwstrength.bootstrap) is beingused for continuos integration. You can check there if the tests are passing.