Fixed breached pwd error messages

This commit is contained in:
Joel Biddle
2023-08-22 20:20:54 +10:00
parent f47a119474
commit 1242d88acb
8 changed files with 81 additions and 70 deletions

View File

@@ -234,8 +234,9 @@
"validate-base": "Password should contain:",
"validate-too-short": "at least 14 characters",
"validate-too-long": "at most 100 characters",
"validate-number": "at least 1 number",
"validate-case": "at least 1 lowercase character",
"validate-number": "at least 1 number"
"validate-breached": "The password you provided is in a list of passwords commonly used on other websites. Please try again with a stronger password."
},
"token": {
"service-tokens": "Service Tokens",

View File

@@ -231,8 +231,8 @@
"validate-base": "La contraseña debe contener:",
"validate-too-short": "como mínimo 14 caracteres",
"validate-too-long": "como máximo 100 caracteres",
"validate-case": "como mínimo 1 letra en minúsculas",
"validate-number": "como mínimo 1 número"
"validate-number": "como mínimo 1 número",
"validate-case": "como mínimo 1 letra en minúsculas"
},
"token": {
"service-tokens": "Tokens de servicio",

View File

@@ -218,8 +218,8 @@
"validate-base": "Le mot de passe doit contenir:",
"validate-too-short": "au moins 14 caractères",
"validate-too-long": "au maximum 100 caractères",
"validate-case": "au moins 1 caractère miniscule",
"validate-number": "au moins 1 chiffre"
"validate-number": "au moins 1 chiffre",
"validate-case": "au moins 1 caractère miniscule"
},
"token": {
"service-tokens": "Jetons de service",
@@ -297,4 +297,4 @@
"step5-subtitle": "Infisical a pour but d'être utilisé avec vos coéquipiers. Invitez-les à le tester.",
"step5-skip": "Passer"
}
}
}

View File

@@ -185,8 +185,8 @@
"validate-base": "비밀번호는 다음 조건을 만족해야 합니다:",
"validate-too-short": "14 글자 이상",
"validate-too-long": "100 자 이하",
"validate-case": "1개 이상의 소문자",
"validate-number": "1개 이상의 숫자"
"validate-number": "1개 이상의 숫자",
"validate-case": "1개 이상의 소문자"
},
"token": {
"add-dialog": {
@@ -257,4 +257,4 @@
"step4-description3": "분실시 접근하거나 복구할 수 없는 시크릿 키가 포함되어 있어요.",
"step4-download": "PDF 다운로드"
}
}
}

View File

@@ -213,8 +213,8 @@
"validate-base": "A senha deve conter:",
"validate-too-short": "pelo menos 14 caracteres",
"validate-too-long": "no máximo 100 caracteres",
"validate-case": "pelo menos 1 caractere minúsculo",
"validate-number": "pelo menos 1 número"
"validate-number": "pelo menos 1 número",
"validate-case": "pelo menos 1 caractere minúsculo"
},
"token": {
"service-tokens": "Tokens de Serviço",
@@ -291,4 +291,4 @@
"step5-subtitle": "Infisical foi feito para ser usado com seus colegas. Convide-os para testar também.",
"step5-skip": "Pular"
}
}
}

View File

@@ -231,8 +231,8 @@
"validate-base": "Şifre kısıtlamaları:",
"validate-too-short": "en az 14 karakter",
"validate-too-long": "en fazla 100 karakter",
"validate-case": "en az 1 küçük harf",
"validate-number": "en az 1 rakam"
"validate-number": "en az 1 rakam",
"validate-case": "en az 1 küçük harf"
},
"token": {
"service-tokens": "Servis Belirteçleri",

View File

@@ -1,3 +1,5 @@
import { checkIsPasswordBreached } from "./checkIsPasswordBreached";
/* eslint-disable no-param-reassign */
interface PasswordCheckProps {
password: string;
@@ -6,17 +8,19 @@ interface PasswordCheckProps {
setPasswordErrorTooLong: (value: boolean) => void;
setPasswordErrorNumber: (value: boolean) => void;
setPasswordErrorLowerCase: (value: boolean) => void;
setPasswordErrorIsBreached: (value: boolean) => void;
}
/**
* This function checks a user password with respect to some criteria.
*/
const passwordCheck = ({
const passwordCheck = async ({
password,
setPasswordErrorTooShort,
setPasswordErrorTooLong,
setPasswordErrorNumber,
setPasswordErrorLowerCase,
setPasswordErrorIsBreached,
errorCheck
}: PasswordCheckProps) => {
if (!password || password.length < 14) {
@@ -57,6 +61,13 @@ const passwordCheck = ({
setPasswordErrorLowerCase(false);
}
if (await checkIsPasswordBreached(password)) {
setPasswordErrorIsBreached(true);
errorCheck = true;
} else {
setPasswordErrorIsBreached(false);
}
// if (!/[A-Z]/.test(password)) {
// setPasswordErrorUpperCase(true);
// errorCheck = true;

View File

@@ -1,21 +1,21 @@
import { checkIsPasswordBreached } from "./checkIsPasswordBreached";
type Errors = {
tooShort?: string,
tooLong?: string,
upperCase?: string,
lowerCase?: string,
number?: string,
specialChar?: string,
repeatedChar?: string,
commonPassword?: string,
breachedPassword?: string
};
tooShort?: string;
tooLong?: string;
upperCase?: string;
lowerCase?: string;
number?: string;
specialChar?: string;
repeatedChar?: string;
commonPassword?: string;
breachedPassword?: string;
};
interface CheckPasswordParams {
password: string;
commonPasswords: string[];
setErrors: (value: Errors) => void;
password: string;
commonPasswords: string[];
setErrors: (value: Errors) => void;
}
/**
@@ -26,62 +26,61 @@ interface CheckPasswordParams {
* - Contains at least 1 lowercase character (a-z)
* - Contains at least 1 number (0-9)
* - Does not contain 3 repeat, consecutive characters
*
*
* The function returns whether or not the password [password]
* passes the minimum requirements above. It sets errors on
* passes the minimum requirements above. It sets errors on
* an erorr object via [setErrors].
*
*
* @param {Object} obj
* @param {String} obj.password - the password to check
* @param {Function} obj.setErrors - set state function to set error object
*/
const checkPassword = async ({
password,
commonPasswords,
setErrors
password,
commonPasswords,
setErrors
}: CheckPasswordParams): Promise<boolean> => {
const errors: Errors = {};
const errors: Errors = {};
const isBreachedPassword = await checkIsPasswordBreached(password)
if (password.length < 14) {
errors.tooShort = "at least 14 characters";
}
if (password.length < 14) {
errors.tooShort = "at least 14 characters";
}
if (password.length > 100) {
errors.tooLong = "at most 100 characters";
}
if (password.length > 100) {
errors.tooLong = "at most 100 characters";
}
if (!/[A-Z]/.test(password)) {
errors.upperCase = "at least 1 uppercase character (A-Z)";
}
if (!/[A-Z]/.test(password)) {
errors.upperCase = "at least 1 uppercase character (A-Z)";
}
if (!/[a-z]/.test(password)) {
errors.lowerCase = "at least 1 lowercase character (a-z)";
}
if (!/[a-z]/.test(password)) {
errors.lowerCase = "at least 1 lowercase character (a-z)";
}
if (!/[0-9]/.test(password)) {
errors.number = "at least 1 number (0-9)";
}
if (!/[0-9]/.test(password)) {
errors.number = "at least 1 number (0-9)";
}
if (!/[!@#$%^&*(),.?":{}|<>]/.test(password)) {
errors.specialChar = "at least 1 special character (!@#$%^&*(),.?)";
}
if (!/[!@#$%^&*(),.?":{}|<>]/.test(password)) {
errors.specialChar = "at least 1 special character (!@#$%^&*(),.?)";
}
if (/([A-Za-z0-9])\1\1\1/.test(password)) {
errors.repeatedChar = "No 3 repeat, consecutive characters";
}
if (commonPasswords.includes(password)) {
errors.commonPassword = "No common passwords";
}
if (/([A-Za-z0-9])\1\1\1/.test(password)) {
errors.repeatedChar = "No 3 repeat, consecutive characters";
}
if (isBreachedPassword) {
errors.breachedPassword = "The password you provided is in a list of passwords commonly used on other websites. Please try again with a stronger password.";
}
setErrors(errors);
return Object.keys(errors).length > 0;
}
if (commonPasswords.includes(password)) {
errors.commonPassword = "No common passwords";
}
export default checkPassword;
if (await checkIsPasswordBreached(password)) {
errors.breachedPassword =
"The password you provided is in a list of passwords commonly used on other websites. Please try again with a stronger password.";
}
setErrors(errors);
return Object.keys(errors).length > 0;
};
export default checkPassword;