1 |
|
2 | var feedback, matching, scoring, time, time_estimates, zxcvbn;
|
3 |
|
4 | matching = require('./matching');
|
5 |
|
6 | scoring = require('./scoring');
|
7 |
|
8 | time_estimates = require('./time_estimates');
|
9 |
|
10 | feedback = require('./feedback');
|
11 |
|
12 | time = function() {
|
13 | return (new Date()).getTime();
|
14 | };
|
15 |
|
16 | zxcvbn = function(password, user_inputs) {
|
17 | var arg, attack_times, i, len, matches, prop, ref, result, sanitized_inputs, start, val;
|
18 | if (user_inputs == null) {
|
19 | user_inputs = [];
|
20 | }
|
21 | start = time();
|
22 | sanitized_inputs = [];
|
23 | for (i = 0, len = user_inputs.length; i < len; i++) {
|
24 | arg = user_inputs[i];
|
25 | if ((ref = typeof arg) === "string" || ref === "number" || ref === "boolean") {
|
26 | sanitized_inputs.push(arg.toString().toLowerCase());
|
27 | }
|
28 | }
|
29 | matching.set_user_input_dictionary(sanitized_inputs);
|
30 | matches = matching.omnimatch(password);
|
31 | result = scoring.most_guessable_match_sequence(password, matches);
|
32 | result.calc_time = time() - start;
|
33 | attack_times = time_estimates.estimate_attack_times(result.guesses);
|
34 | for (prop in attack_times) {
|
35 | val = attack_times[prop];
|
36 | result[prop] = val;
|
37 | }
|
38 | result.feedback = feedback.get_feedback(result.score, result.sequence);
|
39 | return result;
|
40 | };
|
41 |
|
42 | module.exports = zxcvbn;
|
43 |
|
44 |
|