diff --git a/src/index.ts b/src/index.ts index 5c067cf..02cde8e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,5 @@ export { uppercaseMatcher } from './matchers/uppercaseMatcher'; +export { minLengthMatcher } from './matchers/minLengthMatcher'; export { lowercaseMatcher } from './matchers/lowercaseMatcher'; export { numberMatcher } from './matchers/numberMatcher'; export { specialMatcher } from './matchers/specialMatcher'; diff --git a/src/matchers/minLengthMatcher.ts b/src/matchers/minLengthMatcher.ts new file mode 100644 index 0000000..50e05bb --- /dev/null +++ b/src/matchers/minLengthMatcher.ts @@ -0,0 +1,19 @@ +import { Matcher, Match } from '@zxcvbn-ts/core/dist/types'; + +export const minLengthMatcher = (minLength: number): Matcher => ({ + Matching: class MinLengthMatcher { + match({ password }: { password: string }): Match[] { + const matches: Match[] = []; + if (password.length < minLength) { + matches.push({ pattern: 'minLength', token: password, i: 0, j: password.length - 1 }); + } + return matches; + } + }, + feedback(_match) { + return { warning: `Password must be at least ${minLength} characters long.`, suggestions: [] }; + }, + scoring(_match) { + return -100; + }, +});