Files
SnowLuma/.pnpm-store/v11/files/ad/ddd08458254a751f28903ff0293ccca6f66db1961f75e5b83772100c0dbc05ba9fe452ea9d06c3d2f977e1f711ed48ef5fe87976e2af2b6992cd6f9130fc32
T
TanTan 2a69b23b47
Dev Build / cleanup (push) Waiting to run
Dev Build / typecheck (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:27:07 +08:00

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