63 lines
2.3 KiB
Plaintext
63 lines
2.3 KiB
Plaintext
'use strict';
|
|
|
|
var Matching = require('./Matching.cjs');
|
|
var TimeEstimates = require('./TimeEstimates.cjs');
|
|
var Feedback = require('./Feedback.cjs');
|
|
var Options = require('./Options.cjs');
|
|
var debounce = require('./utils/debounce.cjs');
|
|
var index = require('./scoring/index.cjs');
|
|
var types = require('./types.cjs');
|
|
|
|
const time = () => new Date().getTime();
|
|
class ZxcvbnFactory {
|
|
constructor(options = {}, customMatchers = {}) {
|
|
this.options = new Options(options, customMatchers);
|
|
this.scoring = new index(this.options);
|
|
this.matching = new Matching(this.options);
|
|
this.feedback = new Feedback(this.options);
|
|
this.timeEstimates = new TimeEstimates.TimeEstimates(this.options);
|
|
}
|
|
estimateAttackTimes(guesses) {
|
|
return this.timeEstimates.estimateAttackTimes(guesses);
|
|
}
|
|
getFeedback(score, sequence) {
|
|
return this.feedback.getFeedback(score, sequence);
|
|
}
|
|
createReturnValue(resolvedMatches, password, start) {
|
|
const matchSequence = this.scoring.mostGuessableMatchSequence(password, resolvedMatches);
|
|
const calcTime = time() - start;
|
|
const attackTimes = this.estimateAttackTimes(matchSequence.guesses);
|
|
return {
|
|
calcTime,
|
|
...matchSequence,
|
|
...attackTimes,
|
|
feedback: this.getFeedback(attackTimes.score, matchSequence.sequence)
|
|
};
|
|
}
|
|
main(password, userInputs) {
|
|
const userInputsOptions = this.options.getUserInputsOptions(userInputs);
|
|
return this.matching.match(password, userInputsOptions);
|
|
}
|
|
check(password, userInputs) {
|
|
const reducedPassword = password.substring(0, this.options.maxLength);
|
|
const start = time();
|
|
const matches = this.main(reducedPassword, userInputs);
|
|
if (matches instanceof Promise) {
|
|
throw new Error('You are using a Promised matcher, please use `zxcvbnAsync` for it.');
|
|
}
|
|
return this.createReturnValue(matches, reducedPassword, start);
|
|
}
|
|
async checkAsync(password, userInputs) {
|
|
const reducedPassword = password.substring(0, this.options.maxLength);
|
|
const start = time();
|
|
const matches = await this.main(reducedPassword, userInputs);
|
|
return this.createReturnValue(matches, reducedPassword, start);
|
|
}
|
|
}
|
|
|
|
exports.Options = Options;
|
|
exports.debounce = debounce;
|
|
exports.MatcherBaseClass = types.MatcherBaseClass;
|
|
exports.ZxcvbnFactory = ZxcvbnFactory;
|
|
//# sourceMappingURL=index.cjs.map
|