58 lines
2.2 KiB
Plaintext
58 lines
2.2 KiB
Plaintext
import Matching from './Matching.mjs';
|
|
import { TimeEstimates } from './TimeEstimates.mjs';
|
|
import Feedback from './Feedback.mjs';
|
|
import Options from './Options.mjs';
|
|
export { default as debounce } from './utils/debounce.mjs';
|
|
import Scoring from './scoring/index.mjs';
|
|
export { MatcherBaseClass } from './types.mjs';
|
|
|
|
const time = () => new Date().getTime();
|
|
class ZxcvbnFactory {
|
|
constructor(options = {}, customMatchers = {}) {
|
|
this.options = new Options(options, customMatchers);
|
|
this.scoring = new Scoring(this.options);
|
|
this.matching = new Matching(this.options);
|
|
this.feedback = new Feedback(this.options);
|
|
this.timeEstimates = new 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);
|
|
}
|
|
}
|
|
|
|
export { Options, ZxcvbnFactory };
|
|
//# sourceMappingURL=index.mjs.map
|