Add check for most common passwords

This commit is contained in:
Tuan Dang
2023-06-07 00:06:35 +01:00
parent c5be497052
commit a8ed187443
9 changed files with 1547 additions and 6 deletions
@@ -5,10 +5,12 @@ type Errors = {
number?: string,
specialChar?: string,
repeatedChar?: string,
commonPassword?: string
};
interface CheckPasswordParams {
password: string;
commonPasswords: string[];
setErrors: (value: Errors) => void;
}
@@ -30,6 +32,7 @@ interface CheckPasswordParams {
*/
const checkPassword = ({
password,
commonPasswords,
setErrors
}: CheckPasswordParams): boolean => {
let errors: Errors = {};
@@ -58,6 +61,10 @@ const checkPassword = ({
errors.repeatedChar = "No 3 repeat, consecutive characters";
}
if (commonPasswords.includes(password)) {
errors.commonPassword = "No common passwords";
}
setErrors(errors);
return Object.keys(errors).length > 0;
}