Skip to content

Commit

Permalink
chore: update usage instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilan Kushnir committed Nov 25, 2024
1 parent 98ec396 commit 5e621fa
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,49 +10,64 @@ npm install zxcvbn-custom-matchers
### Usage
```ts
import { zxcvbnOptions } from '@zxcvbn-ts/core';
import {
import {
lowercaseMatcher,
numberMatcher,
specialMatcher,
uppercaseMatcher
uppercaseMatcher,
minLengthMatcher
} from 'zxcvbn-custom-matchers';

// Add the matchers
zxcvbnOptions.addMatcher('lowercaseMatcher', lowercaseMatcher);
zxcvbnOptions.addMatcher('numberMatcher', numberMatcher);
zxcvbnOptions.addMatcher('specialMatcher', specialMatcher);
zxcvbnOptions.addMatcher('uppercaseMatcher', uppercaseMatcher);
zxcvbnOptions.addMatcher('lowercase', lowercaseMatcher);
zxcvbnOptions.addMatcher('number', numberMatcher);
zxcvbnOptions.addMatcher('special', specialMatcher);
zxcvbnOptions.addMatcher('uppercase', uppercaseMatcher);
zxcvbnOptions.addMatcher('minLength', minLengthMatcher(10));

// Use zxcvbn as usual
import { zxcvbn } from '@zxcvbn-ts/core';
const result = zxcvbn('password123');
console.log(result);
```

>Note: When adding a custom matcher with addMatcher, the first parameter (a string) should be the same as the matcher's pattern.
## Matchers Description

This project includes several matchers that enforce specific character requirements in passwords. Each matcher checks for a particular type of character and provides feedback and scoring.

### Uppercase Matcher

- **Pattern**: `uppercase`
- **Purpose**: Ensures the password contains at least one uppercase letter.
- **Feedback**: Suggests including at least one uppercase letter if missing.
- **Scoring**: Returns a score of `-100` if missing uppercase letters.
- **Scoring**: Returns a score of `1` if missing uppercase letters.

### Lowercase Matcher

- **Pattern**: `lowercase`
- **Purpose**: Ensures the password contains at least one lowercase letter.
- **Feedback**: Suggests including at least one lowercase letter if missing.
- **Scoring**: Returns a score of `-100` if missing lowercase letters.
- **Scoring**: Returns a score of `1` if missing lowercase letters.

### Number Matcher

- **Pattern**: `number`
- **Purpose**: Ensures the password contains at least one number.
- **Feedback**: Suggests including at least one number if missing.
- **Scoring**: Returns a score of `-100` if missing numbers.
- **Scoring**: Returns a score of `1` if missing numbers.

### Special Character Matcher

- **Pattern**: `special`
- **Purpose**: Ensures the password contains at least one special character (e.g., !, @, #, $, etc.).
- **Feedback**: Suggests including at least one special character if missing.
- **Scoring**: Returns a score of `-100` if missing special characters.
- **Scoring**: Returns a score of `1` if missing special characters.

### Minimum Length Matcher

- **Pattern**: `minLength`
- **Purpose**: Ensures the password meets the minimum length requirement.
- **Feedback**: Suggests the password must be at least the specified length if shorter.
- **Scoring**: Returns a score of `1` if the password is shorter than the specified length.

0 comments on commit 5e621fa

Please sign in to comment.