UNPKG

@contentpass/zxcvbn

Version:

realistic password strength estimation

53 lines (44 loc) 1.66 kB
// Generated by CoffeeScript 1.12.7 var feedback, matching, scoring, time, time_estimates, zxcvbn; matching = require('./matching'); scoring = require('./scoring'); time_estimates = require('./time_estimates'); feedback = require('./feedback'); time = function() { return (new Date()).getTime(); }; zxcvbn = function(password, options) { var arg, attack_times, feedback_messages, i, len, matches, prop, ref, ref1, ref2, result, sanitized_inputs, start, user_inputs, val; if (options == null) { options = {}; } if (options instanceof Array) { user_inputs = options; } else if (typeof options === 'object') { user_inputs = (ref = options.user_inputs) != null ? ref : [], feedback_messages = (ref1 = options.feedback_messages) != null ? ref1 : {}; } else { user_inputs = []; feedback_messages = {}; } start = time(); sanitized_inputs = []; for (i = 0, len = user_inputs.length; i < len; i++) { arg = user_inputs[i]; if ((ref2 = typeof arg) === "string" || ref2 === "number" || ref2 === "boolean") { sanitized_inputs.push(arg.toString().toLowerCase()); } } matching.set_user_input_dictionary(sanitized_inputs); matches = matching.omnimatch(password); result = scoring.most_guessable_match_sequence(password, matches); result.calc_time = time() - start; attack_times = time_estimates.estimate_attack_times(result.guesses); for (prop in attack_times) { val = attack_times[prop]; result[prop] = val; } result.feedback = feedback.get_feedback(result.score, result.sequence, feedback_messages); return result; }; module.exports = zxcvbn; //# sourceMappingURL=main.js.map