UNPKG

899 Btext/coffeescriptView Raw
1matching = require './matching'
2scoring = require './scoring'
3time_estimates = require './time_estimates'
4feedback = require './feedback'
5
6time = -> (new Date()).getTime()
7
8zxcvbn = (password, user_inputs = []) ->
9 start = time()
10 # reset the user inputs matcher on a per-request basis to keep things stateless
11 sanitized_inputs = []
12 for arg in user_inputs
13 if typeof arg in ["string", "number", "boolean"]
14 sanitized_inputs.push arg.toString().toLowerCase()
15 matching.set_user_input_dictionary sanitized_inputs
16 matches = matching.omnimatch password
17 result = scoring.most_guessable_match_sequence password, matches
18 result.calc_time = time() - start
19 attack_times = time_estimates.estimate_attack_times result.guesses
20 for prop, val of attack_times
21 result[prop] = val
22 result.feedback = feedback.get_feedback result.score, result.sequence
23 result
24
25module.exports = zxcvbn