Skip to content

Commit

Permalink
fix: add min length matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilan Kushnir committed Nov 24, 2024
1 parent 375530d commit eb2b91b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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';
19 changes: 19 additions & 0 deletions src/matchers/minLengthMatcher.ts
Original file line number Diff line number Diff line change
@@ -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;
},
});

0 comments on commit eb2b91b

Please sign in to comment.