Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | 1x 104x 103x 78x 25x 25x | import type { AbstractControl, ValidationErrors, ValidatorFn } from '@angular/forms';
import { passwordStrength } from 'check-password-strength';
import { PASSWORDS } from '~/app/shared/constants';
import { getPasswordControlValue } from './util';
/**
* Validator for new password complexity based on [check-password-strength](https://github.com/deanilvincent/check-password-strength)
*/
export const passwordStrengthValidator: ValidatorFn = (control: AbstractControl<unknown>): ValidationErrors | null => {
const value = getPasswordControlValue(control);
// Like Validators.email, rely on Validators.required to check for blank passwords.
if (value == undefined) {
return null; // eslint-disable-line unicorn/no-null -- ValidatorFn returns null
}
const strength = passwordStrength(value);
return strength.id < PASSWORDS.minStrength ? { passwordstrength: strength.value } : null; // eslint-disable-line unicorn/no-null
};
|