UNPKG

@contentpass/zxcvbn

Version:

realistic password strength estimation

34 lines (29 loc) 1.15 kB
matching = require './matching' scoring = require './scoring' time_estimates = require './time_estimates' feedback = require './feedback' time = -> (new Date()).getTime() zxcvbn = (password, options = {}) -> if options instanceof Array user_inputs = options # backward-compatibility else if typeof options == 'object' { user_inputs = [], feedback_messages = {}} = options else user_inputs = [] feedback_messages = {} start = time() # reset the user inputs matcher on a per-request basis to keep things stateless sanitized_inputs = [] for arg in user_inputs if typeof arg in ["string", "number", "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, val of attack_times result[prop] = val result.feedback = feedback.get_feedback result.score, result.sequence, feedback_messages result module.exports = zxcvbn