-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathapi.html
550 lines (509 loc) · 22.9 KB
/
api.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
<!DOCTYPE html>
<html>
<head>
<title>Password Score</title>
<link rel="stylesheet" type="text/css" href="docs/css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="docs/css/prettify.css">
<script type="text/javascript" src="docs/js/jquery.js"></script>
<script type="text/javascript" src="docs/js/jquery.tmpl.js"></script>
<script type="text/javascript" src="docs/js/prettify.js"></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js?config=TeX-MML-AM_CHTML'></script>
<script type="text/javascript">
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
});
$(document).ready(function() {
window.prettyPrint() && prettyPrint();
});
</script>
</head>
<body>
<a href="https://github.com/davidstutz/password-score"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png" alt="Fork me on GitHub"></a>
<div class="container">
<h1>Password Score</h1>
<hr>
<ul class="nav nav-pills">
<li><a href="index.html">Demo</a></li>
<li><a href="statistics.html">Statistics</a></li>
<li class="active"><a href="#">API</a></li>
<li><a href="docs.html">Documentation</a></li>
<li><a href="tests/SpecRunner.html" target="_blank">Tests</a></li>
</ul>
<hr>
<h2>Score</h2>
<div class="row">
<div class="col-md-8">
<p>
The <code>Score</code> class is used to calculate entropy scores of passwords. The entropy score is directly proportional to the strength of a password. The score can be calculated using a naive approach - mostly overestimating the strength of simple passwords - or using a more sophisticated approach - aiming to underestimate passwords such that users are encouraged to choose stronger passwords.
</p>
<p>
The class can easily be used to build a strength meter as for example <a href="https://github.com/davidstutz/bootstrap-strength-meter" target="_blank">Bootstrap Strength Meter</a>.
</p>
</div>
<div class="col-md-4">
<div class="well well-sm">
<ul class="nav nav-list">
<li><a href="#constructor">Constructor</a></li>
<li><a href="#calculateEntropyScore">Score.calculateEntropyScore</a></li>
<li><a href="#calculateBruteForceEntropy">Score.calculateBruteForceEntropy</a></li>
<li><a href="#calculateAverageTimeToCrack">Score.calculateAverageTimeToCrack</a></li>
<li><a href="#cache">Score.cache</a></li>
</ul>
</div>
</div>
</div>
<h3><a id="constructor"></a>Constructor</h3>
</div>
<div class="stripe">
<div class="container">
<pre class="prettyprint">
new Score(password);
</pre>
</div>
</div>
<div class="container">
<table class="table table-gray">
<tbody>
<tr>
<th>Parameters</th>
<td>
<dl>
<dt>password</dt>
<dd>
The non-empty password to score.
</dd>
</dl>
</td>
</tr>
</tbody>
</table>
<h3><a id="calculateEntropyScore"></a>Score.calculateEntropyScore</h3>
<p>
This method is used to calculate a realistic entropy score of the password. This score can be used to reliably estimate the strength of a password.
</p>
</div>
<div class="stripe">
<div class="container">
<pre class="prettyprint">
score = new Score(password);
score.calculateEntropyScore()
score.calculateEntropyScore(options);
score.calculateEnoptryScore(options, append);
</pre>
</div>
</div>
<div class="container">
<table class="table table-gray">
<tbody>
<tr>
<th>Parameters</th>
<td>
<dl>
<dt>options</dt>
<dd>
<p>
The optiosn to configure how to calculate the score. If not provided, the default options are used, see below. For details on the available options see the <a href="docs.html">Documentation</a>.
</p>
<div class="box" style="width:90%">
<pre class="prettyprint linenums">
var defaultOptions = [
{
'type': 'dictionary',
'leet': true,
'key': 'en',
'dictionary': {"you":1,"the":2,"to":3, /* see data/json/last.json ... */}
},
{
'type': 'dictionary',
'leet': true,
'key': 'de',
'dictionary': {"ich":1,"sie":2,"das":3, /* see data/json/last.json ... */}
},
{
'type': 'dictionary',
'leet': true,
'key': 'countries_en',
'dictionary': {"afghanistan":1,"albania":2,"algeria":3, /* see data/json/countries-en.json ... */}
},
{
'type': 'dictionary',
'leet': true,
'key': 'countries_de',
'dictionary': {"afghanistan":1,"alandinseln":2,"albanien":3, /* see data/json/countries-de.json ... */}
},
{
'type': 'dictionary',
'leet': true,
'key': 'cities',
'dictionary': {"Shanghai":1,"Mumbai":2,"Mexico City":3, /* see data/json/cities.json ... */}
},
{
'type': 'dictionary',
'leet': true,
'key': 'last',
'dictionary': {"smith":1,"johnson":2,"williams":3, /* see data/json/last.json ... */}
},
{
'type': 'dictionary',
'leet': true,
'key': 'female',
'dictionary': {"mary":1,"patricia":2,"linda":3, /* see data/json/last.json ... */}
},
{
'type': 'dictionary',
'leet': true,
'key': 'male',
'dictionary': {"james":1,"john":2,"robert":3, /* see data/json/last.json ... */}
},
{
'type': 'dictionary',
'leet': true,
'key': 'passwords',
'dictionary': {"password":1,"123456":2,"12345678":3, /* see data/json/last.json ... */}
},
{
'type': 'keyboard',
'key': 'qwerty',
'keyboard': this.keyboards.QWERTY
},
{
'type': 'keyboard',
'key': 'qwertz',
'keyboard': this.keyboards.QWERTZ
},
{
'type': 'keyboard',
'key': 'qwerty_numpad',
'keyboard': this.keyboards.QWERTYNumpad
},
{
'type': 'keyboard',
'key': 'qwertz_numpad',
'keyboard': this.keyboards.QWERTZNumpad
},
{
'type': 'repetition',
'key': 'repetition'
},
{
'type': 'sequences',
'key': 'sequences'
},
{
'type': 'dates',
'key': 'dates'
}
];
</pre>
</div>
</dd>
<dt>append</dt>
<dd>
The default options given above can be used as base such that additional dictionaries can easily be added using the <code>options</code> parameter. However, the default dictionaries can also be replaced by providing custom <code>options</code> and setting <code>append</code> to <code>false</code>, that is the provided options are not appended to the default ones.
</dd>
</dl>
</td>
</tr>
<tr>
<th>Returns</th>
<td>
The method returns the calculated score which may range from zero to infinity. Check the <a href="index.html">demonstration</a> to get a feeling for the calculated score.
</td>
</tr>
</tbody>
</table>
<h3><a id="calculateBruteForceEntropy"></a>Score.calculateBruteForceEntropy</h3>
<p>
This method is used to calculate a naive entropy score, that is the password is not searched for patterns or dictionary entries.
</p>
</div>
<div class="stripe">
<div class="container">
<pre class="prettyprint">
score = new Score(password);
score.calculateBruteForceEntropy();
</pre>
</div>
</div>
<div class="container">
<table class="table table-gray">
<tbody>
<tr>
<th>Returns</th>
<td>
The method returns the naive entropy score.
</td>
</tr>
</tbody>
</table>
<h3><a id="calculateAverageTimeToCrack"></a>Score.calculateAverageTimeToCrack</h3>
<p>
This method can be used to calculate the average number of seconds needed to crack a password with the given entropy score. The method assumes that it takes $0.005$ seconds to check a single password.
</p>
</div>
<div class="stripe">
<div class="container">
<pre class="prettyprint">
score = new Score(password);
var entropy = score.calculateBruteForceEntropy();
score.calculateAverageTimeToCrack(entropy, cores);
</pre>
</div>
</div>
<div class="container">
<table class="table table-gray">
<tbody>
<tr>
<th>Parameters</th>
<td>
<dl>
<dt>entropy</dt>
<dd>The entropy of the password as calculated by <code>calculateEntropyScore</code> or <code>calculateBruteForceEntropy</code>.</dd>
<dt>cores</dt>
<dd>The number of cores used to crack the password.</dd>
</dl>
</td>
</tr>
<tr>
<th>Returns</th>
<td>
The method returns the number of seconds needed on average to crack the a password with the given entropy score.
</td>
</tr>
</tbody>
</table>
<h3><a id="cache"></a>Score.cache</h3>
<p>
Running <code>calculateEntropyScore</code> or <code>calculateBruteForceEntropy</code> will cause Password Score to save some details in <code>Score.cache</code>:
</p>
<table class="table table-gray">
<tbody>
<tr>
<th>Score.cache.entropy</th>
<td>The entropy score calculated by <code>calculateEntropyScore</code>.</td>
</tr>
<tr>
<th>Score.cache.minimumMatches</th>
<td>The array of all patterns found by Password Score and corresponding to the calculated entropy score.</td>
</tr>
<tr>
<th>Score.cache[key]</th>
<td>
<p>
<code>key</code> may be any string given during the configuration when using <code>calculateEntropyScore</code>, see the documentation of <code>calculateEntropyScore</code> or the following example:
</p>
<div class="box" style="width:90%">
<pre class="prettyprint linenums">
// Remember the first dictionary of the default options:
var options = [
{
'type': 'dictionary',
'leet': true,
'key': 'en',
'dictionary': {"you":1,"the":2,"to":3, /* see data/json/last.json ... */}
},
];
// ...
score = new Score(password);
score.calculateEntropyScore();
console.log(score.cache['en']);
</pre>
</div>
</td>
</tr>
<tr>
<th>Score.cache.naiveEntropy</th>
<td>The entropy calculated by <code>calculateBruteForceEntropy</code>.</td>
</tr>
<tr>
<th>Score.cache.clear</th>
<td>This method clears the cache. However, it is not necessary ot use this while not changing the configuration as all relevant information is overwritten when running <code>calculateEntropyScore</code> or <code>calculateBruteForceEntropy</code> repeatedly.</td>
</tr>
</tbody>
</table>
<h2>Keyboard</h2>
<div class="row">
<div class="col-md-8">
<p>
The <code>Keyboard</code> class is used to represent a specific keyboard layout as undirected graph. This class is mainly used by the <code>Score</code> class to find keyboard patterns.
</p>
</div>
<div class="col-md-4">
<div class="well well-sm">
<ul class="nav nav-list">
<li><a href="#keyboard-constructor">Constructor</a></li>
<li><a href="#areAdjacent">Keyboard.areAdjacent</a></li>
</ul>
</div>
</div>
</div>
<h3><a id="keyboard-constructor"></a>Constructor</h3>
</div>
<div class="stripe">
<div class="container">
<pre class="prettyprint">
new Keyboard(adjacencyList, averageDegree);
</pre>
</div>
</div>
<div class="container">
<table class="table table-gray">
<tbody>
<tr>
<th>Parameters</th>
<td>
<dl>
<dt>adjacencyList</dt>
<dd>
<p>
A keyboard is primarily defined by an adjacency list, that is each key on the keyboard has six neighbors. However, the adjacency list always includes the key itself. An example is shown below:
</p>
<div class="box" style="width:90%">
<pre class="prettyprint">
QWERTY: new Keyboard({
'~': [null, null, null, '~`', '1!', null, null], // 1
'`': [null, null, null, '~`', '1!', null, null], // 1
'1': [null, null, '`~', '1!', '2@', null, 'qQ'], // 3
'!': [null, null, '`~', '1!', '2@', null, 'qQ'], // 3
'2': [null, null, '1!', '2@', '3#', 'qQ', 'wW'], // 4
'@': [null, null, '1!', '2@', '3#', 'qQ', 'wW'], //4
'3': [null, null, '2@', '3#', '4$', 'wW', 'eE'], //4
'#': [null, null, '2@', '3#', '4$', 'wW', 'eE'], //4
'4': [null, null, '3#', '4$', '5%', 'eE', 'rR'], //4
'$': [null, null, '3#', '4$', '5%', 'eE', 'rR'], //4
'5': [null, null, '4$', '5%', '6^', 'rR', 'tT'], //4
'%': [null, null, '4$', '5%', '6^', 'rR', 'tT'], //4
'6': [null, null, '5%', '6^', '7&', 'tT', 'yY'], //4
'^': [null, null, '5%', '6^', '7&', 'tT', 'yY'], //4
'7': [null, null, '6^', '7&', '8*', 'yY', 'uU'], //4
'&': [null, null, '6^', '7&', '8*', 'yY', 'uU'], //4
'8': [null, null, '7&', '8*', '9(', 'uU', 'iI'], // 4
'*': [null, null, '7&', '8*', '9(', 'uU', 'iI'], // 4
'9': [null, null, '8*', '9(', '0)', 'iI', 'oO'], // 4
'(': [null, null, '8*', '9(', '0)', 'iI', 'oO'], // 4
'0': [null, null, '9(', '0)', '-_', 'oO', 'pP'], // 4
')': [null, null, '9(', '0)', '-_', 'oO', 'pP'], // 4
'-': [null, null, '0)', '-_', '=+', 'pP', '[{'], // 4
'_': [null, null, '0)', '-_', '=+', 'pP', '[{'], // 4
'=': [null, null, '-_', '=+', '\\|', '{[', '}]'], // 4
'+': [null, null, '-_', '=+', '\\|', '{[', '}]'], // 4
'\\': [null, null, '=+', '\\|', null, '}]', null], // 2
'|': [null, null, '=+', '\\|', null, '}]', null], // 2
'q': ['1!', '2@', null, 'qQ', 'wW', null, 'aA'], // 4
'Q': ['1!', '2@', null, 'qQ', 'wW', null, 'aA'], // 4
'w': ['2@', '3#', 'qQ', 'wW','eE', 'aA', 'sS'], // 6
'W': ['2@', '3#', 'qQ', 'wW','eE', 'aA', 'sS'], // 6
'e': ['3#', '4$', 'wW', 'eE', 'rR', 'sS', 'dD'], // 6
'E': ['3#', '4$', 'wW', 'eE', 'rR', 'sS', 'dD'], // 6
'r': ['4$', '5%', 'eE', 'rR', 'tT', 'dD', 'fF'], // 6
'R': ['4$', '5%', 'eE', 'rR', 'tT', 'dD', 'fF'], // 6
't': ['5%', '6^', 'rR', 'tT', 'yY', 'fF', 'gG'], // 6
'T': ['5%', '6^', 'rR', 'tT', 'yY', 'fF', 'gG'], // 6
'y': ['6^', '7&', 'tT', 'yY', 'uU', 'gG', 'hH'], // 6
'Y': ['6^', '7&', 'tT', 'yY', 'uU', 'gG', 'hH'], // 6
'u': ['7&', '8*', 'yY', 'uU', 'iI', 'hH', 'jJ'], // 6
'U': ['7&', '8*', 'yY', 'uU', 'iI', 'hH', 'jJ'], // 6
'i': ['8*', '9(', 'uU', 'iI', 'oO', 'jJ', 'kK'], // 6
'I': ['8*', '9(', 'uU', 'iI', 'oO', 'jJ', 'kK'], // 6
'o': ['9(', '0)', 'iI', 'oO', 'pP', 'kK', 'lL'], // 6
'O': ['9(', '0)', 'iI', 'oO', 'pP', 'kK', 'lL'], // 6
'p': ['0)', '-_', 'oO', 'pP', '[{', 'lL', ':;'], // 6
'P': ['0)', '-_', 'oO', 'pP', '[{', 'lL', ':;'], // 6
'[': ['-_', '=+', 'pP', '[{', ']}', ':;', '\'"'], // 6
'{': ['-_', '=+', 'pP', '[{', ']}', ':;', '\'"'], // 6
']': ['=+', '\\|', '[{', ']}', null, '\'"', null], // 4
'}': ['=+', '\\|', '[{', ']}', null, '\'"', null], // 4
'a': ['qQ', 'wW', null, 'aA', 'sS', null, 'zZ'], // 4
'A': ['qQ', 'wW', null, 'aA', 'sS', null, 'zZ'], // 4
's': ['wW', 'eE', 'aA', 'sS', 'dD', 'zZ', 'xX'], // 6
'S': ['wW', 'eE', 'aA', 'sS', 'dD', 'zZ', 'xX'], // 6
'd': ['eE', 'rR', 'sS', 'dD', 'fF', 'xX', 'cC'], // 6
'D': ['eE', 'rR', 'sS', 'dD', 'fF', 'xX', 'cC'], // 6
'f': ['rR', 'tT', 'dD', 'fF', 'gG', 'cC', 'vV'], // 6
'F': ['rR', 'tT', 'dD', 'fF', 'gG', 'cC', 'vV'], // 6
'g': ['tT', 'yY', 'fF', 'gG', 'hH', 'vV', 'bB'], // 6
'G': ['tT', 'yY', 'fF', 'gG', 'hH', 'vV', 'bB'], // 6
'h': ['yY', 'uU', 'gG', 'hH', 'jJ', 'bB', 'nN'], // 6
'H': ['yY', 'uU', 'gG', 'hH', 'jJ', 'bB', 'nN'], // 6
'j': ['uU', 'iI', 'hH', 'jJ', 'kK', 'nN', 'mM'], // 6
'J': ['uU', 'iI', 'hH', 'jJ', 'kK', 'nN', 'mM'], // 6
'k': ['iI', 'oO', 'jJ', 'kK', 'lL', 'mM', ',;'], // 6
'K': ['iI', 'oO', 'jJ', 'kK', 'lL', 'mM', ',;'], // 6
'l': ['oO', 'pP', 'kK', 'lL', ':;', ',<', '.>'], // 6
'L': ['oO', 'pP', 'kK', 'lL', ':;', ',<', '.>'], // 6
':': ['pP', '[{', 'lL', ':;', '\'"', '.>', '?/'], // 6
';': ['pP', '[{', 'lL', ':;', '\'"', '.>', '?/'], // 6
'\'': ['[{', ']}', ':;', '\'"', null, '?/', null], // 5
'"': ['[{', ']}', ':;', '\'"', null, '?/', null], // 5
'z': ['aA', 'sS', null, 'zZ', 'xX', null, null], // 4
'Z': ['aA', 'sS', null, 'zZ', 'xX', null, null], // 4
'x': ['sS', 'dD', 'zZ', 'xX', 'cC', null, null], // 4
'X': ['sS', 'dD', 'zZ', 'xX', 'cC', null, null], // 4
'c': ['dD', 'fF', 'xX', 'cC', 'vV', null, null], // 4
'C': ['dD', 'fF', 'xX', 'cC', 'vV', null, null], // 4
'v': ['fF', 'gG', 'cC', 'vV', 'bB', null, null], // 4
'V': ['fF', 'gG', 'cC', 'vV', 'bB', null, null], // 4
'b': ['gG', 'hH', 'vV', 'bB', 'nN', null, null], // 4
'B': ['gG', 'hH', 'vV', 'bB', 'nN', null, null], // 4
'n': ['hH', 'jJ', 'bB', 'nN', 'mM', null, null], // 4
'N': ['hH', 'jJ', 'bB', 'nN', 'mM', null, null], // 4
'm': ['jJ', 'kK', 'nN', 'mM', ',<', null, null], // 4
'M': ['jJ', 'kK', 'nN', 'mM', ',<', null, null], // 4
',': ['kK', 'lL', 'mM', ',<', '.>', null, null], // 4
'<': ['kK', 'lL', 'mM', ',<', '.>', null, null], // 4
'.': ['lL', ':;', ',<', '.>', '/?', null, null], // 4
'>': ['lL', ':;', ',<', '.>', '/?', null, null], // 4
'/': [':;', '\'"', '.>', '/?', null, null, null], // 3
'?': [':;', '\'"', '.>', '/?', null, null, null] // 3
}, 4.571428571), // Average number of neighbors.
</pre>
</div>
</dd>
<dt>averageDegree</dt>
<dd>The average number of neighbors for each key (excluding the key itself).</dd>
</dl>
</td>
</tr>
</tbody>
</table>
<h3><a id="areAdjacent"></a>Keyboard.areAdjacent</h3>
<p>This method checks whether two key are adjacent in the keyboard.</p>
</div>
<div class="stripe">
<div class="container">
<pre class="prettyprint">
keyboard = new Keyboard(adjacencyList, averageDegree);
keyboard.areAdjacent(a, b);
</pre>
</div>
</div>
<div class="container">
<table class="table table-gray">
<tbody>
<tr>
<th>Parameters</th>
<td>
<dl>
<dt>a</dt>
<dd>The first character (a single character).</dd>
<dt>b</dt>
<dd>The second character (a single character).</dd>
</dl>
</td>
</tr>
<tr>
<th>Returns</th>
<td><code>true</code> if and only if the characters <code>a</code> and <code>b</code> are adjacent in the keyboard.</td>
</tr>
</tbody>
</table>
</div>
<hr>
<div class="container">
<p>
© 2013 - 2018
<a href="http://davidstutz.de">David Stutz</a> - <a href="http://opensource.org/licenses/BSD-3-Clause">BSD 3-Clause License</a> - <a href="https://davidstutz.de/impressum/">Impressum</a> - <a href="https://davidstutz.de/datenschutz/">Datenschutz</a>
</p>
</div>
</body>
</html>