1 | # jQuery Entropizer |
---|
2 | |
---|
3 | *Password strength meter jQuery plugin* |
---|
4 | |
---|
5 | For the standalone Entropizer engine, click [here](https://github.com/jreesuk/entropizer) |
---|
6 | |
---|
7 | ## What is jQuery Entropizer? |
---|
8 | |
---|
9 | jQuery Entropizer is a simple, lightweight jQuery plugin that uses the [Entropizer engine](https://github.com/jreesuk/entropizer) to |
---|
10 | calculate password entropy. It's easy to set up and provides several hooks to customize the UI. |
---|
11 | |
---|
12 | jQuery Entropizer supports [AMD](http://requirejs.org/) and [CommonJS](http://wiki.commonjs.org/wiki/CommonJS). It is available |
---|
13 | as a [bower](http://bower.io/) component. |
---|
14 | |
---|
15 | ## Demos |
---|
16 | |
---|
17 | Some basic demos can be found [here](http://jreesuk.github.io/jquery-entropizer/). |
---|
18 | |
---|
19 | ## Getting Started |
---|
20 | |
---|
21 | This plugin requires both [jQuery](http://jquery.com/) (1.7.2+) and [Entropizer](https://github.com/jreesuk/entropizer). |
---|
22 | |
---|
23 | Basic usage: |
---|
24 | |
---|
25 | ```html |
---|
26 | <label for="pwd">Please enter a password</label> |
---|
27 | <input type="password" id="pwd" name="pwd" /> |
---|
28 | <div id="meter"></div> |
---|
29 | ``` |
---|
30 | |
---|
31 | ```js |
---|
32 | // Creates a default Entropizer meter inside #meter and watches the first password field on the |
---|
33 | // page by default |
---|
34 | $('#meter').entropizer(); |
---|
35 | ``` |
---|
36 | |
---|
37 | Options and examples: |
---|
38 | |
---|
39 | ```js |
---|
40 | // Create an Entropizer meter using custom options |
---|
41 | $('#meter').entropizer({ |
---|
42 | |
---|
43 | // The input field to watch: any selector, DOM element or jQuery instance |
---|
44 | // Default: 'input[type=password]:first' |
---|
45 | target: '#pwd', |
---|
46 | |
---|
47 | // The event(s) upon which to update the meter UI |
---|
48 | // Default: 'keydown keyup' |
---|
49 | on: 'keydown', |
---|
50 | |
---|
51 | // Used to calculate the percentage of the bar to fill (see map function below) |
---|
52 | // Default: 100 |
---|
53 | maximum: 80, |
---|
54 | |
---|
55 | // An array of ranges to use when classifying password strength. Used internally by default map |
---|
56 | // function and can be used publicly via $.entropizer.classify(value, buckets). Properties |
---|
57 | // 'min' and 'max' are used to calculate which bucket to use - upon finding a match, an object |
---|
58 | // containing all the other properties is returned, e.g. below, a value of 42 returns |
---|
59 | // { message: ':)' } |
---|
60 | // Default: 4 ranges with strength and color properties (see source for values) |
---|
61 | buckets: [ |
---|
62 | { max: 40, message: ':(' }, |
---|
63 | { min: 40, max: 60, message: ':)' }, |
---|
64 | { min: 60, message: ':D' } |
---|
65 | ], |
---|
66 | |
---|
67 | // Either an Entropizer engine options object or an Entropizer instance |
---|
68 | // Default: a new Entropizer instance with default settings |
---|
69 | engine: { |
---|
70 | classes: ['lowercase', 'uppercase', 'numeric'] |
---|
71 | }, |
---|
72 | |
---|
73 | // A callback controlling UI creation - takes a jQuery instance representing the container |
---|
74 | // and returns an object containing UI components for access in update and destroy |
---|
75 | // Default: creates a track element (the bar background), a bar element and a text element |
---|
76 | create: function(container) { |
---|
77 | var bar = $('<div>').appendTo(container); |
---|
78 | return { foo: bar }; |
---|
79 | }, |
---|
80 | |
---|
81 | // A callback controlling UI cleanup - takes the UI object created by create |
---|
82 | // Default: removes the track, bar and text elements |
---|
83 | destroy: function(ui) { |
---|
84 | ui.foo.remove(); |
---|
85 | }, |
---|
86 | |
---|
87 | // A callback that maps the raw entropy value to an object passed to update. First argument is |
---|
88 | // the number of bits of entropy, second argument is an object containing all properties on |
---|
89 | // the options object apart from target, on, engine and the callbacks (i.e. by default, just |
---|
90 | // maximum and buckets) |
---|
91 | // Default: uses maximum and buckets above to return an object with entropy, percent, strength |
---|
92 | // and color properties |
---|
93 | map: function(entropy, mapOptions) { |
---|
94 | return $.extend({ entropy: entropy }, $.entropizer.classify(entropy, mapOptions.buckets)); |
---|
95 | }, |
---|
96 | |
---|
97 | // A callback controlling UI updates - takes the data returned by map and the ui object |
---|
98 | // Default: updates the width and background color of the bar, and displays the number of bits |
---|
99 | update: function(data, ui) { |
---|
100 | ui.foo.text(data.entropy.toFixed(0) + ' ' + data.message); |
---|
101 | } |
---|
102 | }); |
---|
103 | ``` |
---|
104 | |
---|
105 | If you need to remove an `entropizer` instance: |
---|
106 | |
---|
107 | ```js |
---|
108 | $('#meter').entropizer('destroy'); |
---|
109 | ``` |
---|
110 | |
---|
111 | This will unbind all Entropizer events from the target and invoke the `destroy` callback. |
---|
112 | |
---|
113 | ## Styling |
---|
114 | |
---|
115 | The default UI creates elements for the track, bar and text - these use the CSS classes |
---|
116 | `entropizer-track`, `entropizer-bar` and `entropizer-text` respectively. Default styles for these |
---|
117 | elements can be found in the provided CSS stylesheet. |
---|
118 | |
---|
119 | ## Engine options |
---|
120 | |
---|
121 | For a guide to Entropizer engine options, see the readme [here](https://github.com/jreesuk/entropizer). |
---|
122 | |
---|
123 | ## Browser compatibility |
---|
124 | |
---|
125 | jQuery Entropizer supports IE6+, Firefox, Chrome and Opera. |
---|