Subversion-Projekte lars-tiefland.cienc

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
5 lars 1
# jQuery Password Strength Meter for Twitter Bootstrap
2
 
3
[![Build Status](https://travis-ci.org/ablanco/jquery.pwstrength.bootstrap.png?branch=master)](https://travis-ci.org/ablanco/jquery.pwstrength.bootstrap)
4
[![Code Climate](https://codeclimate.com/github/ablanco/jquery.pwstrength.bootstrap.png)](https://codeclimate.com/github/ablanco/jquery.pwstrength.bootstrap)
5
[![devDependency Status](https://david-dm.org/ablanco/jquery.pwstrength.bootstrap/dev-status.png)](https://david-dm.org/ablanco/jquery.pwstrength.bootstrap#info=devDependencies)
6
 
7
The jQuery Password Strength Meter is a plugin for Twitter Bootstrap that
8
provides rulesets for visualy displaying the quality of a users typed in
9
password.
10
 
11
Dual licensed under the MIT and GPL licenses. You can choose the one that
12
suits your purposes better.
13
 
14
[npm entry](https://www.npmjs.com/package/pwstrength-bootstrap)
15
 
16
 
17
## Requirements
18
 
19
* jQuery 1.7 or higher
20
* Bootstrap 2, 3 or 4
21
 
22
### Not using Bootstrap?
23
 
24
This plugin currently relies heavily on Bootstrap and it is not possible to
25
use it with another framework without making big changes in the code or
26
forgetting completely about the UI feedback.
27
 
28
Forks to use it with another frameworks that I know of:
29
 
30
* [Zurb Foundation fork by edtownend](https://github.com/edtownend/jquery.pwstrength.foundation)
31
 
32
 
33
## How to use it
34
 
35
Just invoke the plugin on the password fields you want to attach a strength
36
meter to. For example, to use it on all the password fields with the default
37
examples:
38
 
39
```javascript
40
    $(':password').pwstrength();
41
```
42
 
43
To apply it only to one input and change the options:
44
 
45
```javascript
46
    $('#passwd1').pwstrength({
47
        ui: { showVerdictsInsideProgressBar: true }
48
    });
49
```
50
 
51
## Options
52
 
53
Click here to find [the complete list of options for the plugin](OPTIONS.md).
54
 
55
 
56
## Methods
57
 
58
Once the plugin has been initialized, it is possible to interact with it
59
through the methods.
60
 
61
 
62
### Force an update
63
 
64
It is possible to force an update on a password strength meter. It will force
65
a new score calculation and an update of the UI elements, the `onKeyUp`
66
callback will be called.
67
 
68
```javascript
69
$("#passwdfield").pwstrength("forceUpdate");
70
```
71
 
72
 
73
### Remove the strength meter
74
 
75
This will remove the data associated to the meter, and the UI elements.
76
 
77
```javascript
78
$("#passwdfield").pwstrength("destroy");
79
```
80
 
81
 
82
### Adding Custom Rules
83
 
84
The plugin comes with the functionality to easily define your own custom rules.
85
The format is as follows:
86
 
87
```javascript
88
$("#passwdfield").pwstrength("addRule", "ruleName", function (options, word, score) {}, rule_score, rule_enabled);
89
```
90
 
91
Example:
92
 
93
```javascript
94
$("#passwdfield").pwstrength("addRule", "testRule", function (options, word, score) {
95
    return word.match(/[a-z].[0-9]/) && score;
96
}, 10, true);
97
```
98
 
99
 
100
### Change the score associated to a rule
101
 
102
It is possible to change the score given by a rule. It works like this:
103
 
104
```javascript
105
$("#passwdfield").pwstrength("changeScore", "wordSequences", -100);
106
```
107
 
108
That would penalize even more the presence of sequences in the password.
109
 
110
 
111
### Activate and deactivate rules
112
 
113
It is also possible to activate or deactivate rules. It as simple as:
114
 
115
```javascript
116
$("#passwdfield").pwstrength("ruleActive", "wordSequences", false);
117
```
118
 
119
That would avoid looking for sequences in the password being tested.
120
 
121
 
122
## Callback Functions
123
 
124
The plugin provides two callback functions, onLoad and onKeyUp.  You can use
125
them like this:
126
 
127
```javascript
128
$(document).ready(function () {
129
    var options = {};
130
    options.common = {
131
        onLoad: function () {
132
            $('#messages').text('Start typing password');
133
        },
134
        onKeyUp: function (evt, data) {
135
            $("#length-help-text").text("Current length: " + $(evt.target).val().length + " and score: " + data.score);
136
        }
137
    };
138
    $(':password').pwstrength(options);
139
});
140
```
141
 
142
 
143
## Extra security
144
 
145
The plugin comes with two validation rules deactivated by default. One checks
146
for too many character repetitions, and the other checks the number of
147
character classes used. An easy way to increase the security of the passwords
148
is to activate this two rules:
149
 
150
```javascript
151
$(document).ready(function () {
152
    var options = {};
153
    options.rules = {
154
        activated: {
155
            wordTwoCharacterClasses: true,
156
            wordRepetitions: true
157
        }
158
    };
159
    $(':password').pwstrength(options);
160
});
161
```
162
 
163
 
164
## Examples
165
 
166
There are some examples in the `examples` directory. Just serve them with any
167
webserver and check them in your browser. Make sure you serve the `examples`
168
directory as the site root. For example:
169
 
170
```bash
171
cd examples
172
python -m SimpleHTTPServer
173
```
174
 
175
And go to [localhost:8000](http://localhost:8000).
176
 
177
Alternatively, you can check-out the examples in a [hosted demo](https://cdn.rawgit.com/ablanco/jquery.pwstrength.bootstrap/master/examples/index.html).
178
 
179
## Build and Test
180
 
181
The build and testing processes rely on [Grunt](http://gruntjs.com/). To use
182
them you need to have [node.js](http://nodejs.org/) and grunt-cli installed on
183
your system. Assuming you have node.js in your Linux system, you'll need to do
184
something like this:
185
 
186
```bash
187
sudo npm install -g grunt-cli
188
```
189
 
190
Now you have the grunt command line utility installed globally.
191
 
192
 
193
### Bundle and minified
194
 
195
To generate the bundle and the minified file you only need to execute this in
196
the project directory:
197
 
198
```bash
199
npm install -d
200
grunt
201
```
202
 
203
It will check the source files, and build a minified version with its
204
corresponding source map. The generated files will be available in the `dist`
205
directory.
206
 
207
 
208
### Testing
209
 
210
To run the tests the only thing you need to do is execute this in the project
211
directory:
212
 
213
```bash
214
npm install -d
215
grunt test
216
```
217
 
218
It will check all the source files with [JSLint](http://jslint.com) and run the
219
tests, which are written with [Jasmine](http://jasmine.github.io/). You'll find
220
the tests source code in the `spec` directory.
221
 
222
[Travis](https://travis-ci.org/ablanco/jquery.pwstrength.bootstrap) is being
223
used for continuos integration. You can check there if the tests are passing.