From 1242d88acb8438f5a5f50aaf92025d42edf05cfe Mon Sep 17 00:00:00 2001 From: Joel Biddle Date: Tue, 22 Aug 2023 20:20:54 +1000 Subject: [PATCH] Fixed breached pwd error messages --- frontend/public/locales/en/translations.json | 3 +- frontend/public/locales/es/translations.json | 4 +- frontend/public/locales/fr/translations.json | 6 +- frontend/public/locales/ko/translations.json | 6 +- .../public/locales/pt-BR/translations.json | 6 +- frontend/public/locales/tr/translations.json | 4 +- .../utilities/checks/PasswordCheck.ts | 13 ++- .../utilities/checks/checkPassword.ts | 109 +++++++++--------- 8 files changed, 81 insertions(+), 70 deletions(-) diff --git a/frontend/public/locales/en/translations.json b/frontend/public/locales/en/translations.json index 506495b3f..84554d8fc 100644 --- a/frontend/public/locales/en/translations.json +++ b/frontend/public/locales/en/translations.json @@ -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", diff --git a/frontend/public/locales/es/translations.json b/frontend/public/locales/es/translations.json index 28e2793cb..b9fe5f335 100644 --- a/frontend/public/locales/es/translations.json +++ b/frontend/public/locales/es/translations.json @@ -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", diff --git a/frontend/public/locales/fr/translations.json b/frontend/public/locales/fr/translations.json index 49edd33fa..00556b1d8 100644 --- a/frontend/public/locales/fr/translations.json +++ b/frontend/public/locales/fr/translations.json @@ -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" } -} \ No newline at end of file +} diff --git a/frontend/public/locales/ko/translations.json b/frontend/public/locales/ko/translations.json index d29a5846c..b40109400 100644 --- a/frontend/public/locales/ko/translations.json +++ b/frontend/public/locales/ko/translations.json @@ -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 다운로드" } -} \ No newline at end of file +} diff --git a/frontend/public/locales/pt-BR/translations.json b/frontend/public/locales/pt-BR/translations.json index e04de50da..805abd126 100644 --- a/frontend/public/locales/pt-BR/translations.json +++ b/frontend/public/locales/pt-BR/translations.json @@ -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" } -} \ No newline at end of file +} diff --git a/frontend/public/locales/tr/translations.json b/frontend/public/locales/tr/translations.json index c98399f7f..a03b9eb2c 100644 --- a/frontend/public/locales/tr/translations.json +++ b/frontend/public/locales/tr/translations.json @@ -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", diff --git a/frontend/src/components/utilities/checks/PasswordCheck.ts b/frontend/src/components/utilities/checks/PasswordCheck.ts index 92d891d97..133eb5a35 100644 --- a/frontend/src/components/utilities/checks/PasswordCheck.ts +++ b/frontend/src/components/utilities/checks/PasswordCheck.ts @@ -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; diff --git a/frontend/src/components/utilities/checks/checkPassword.ts b/frontend/src/components/utilities/checks/checkPassword.ts index 0ef1e949b..4f0d0a523 100644 --- a/frontend/src/components/utilities/checks/checkPassword.ts +++ b/frontend/src/components/utilities/checks/checkPassword.ts @@ -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 => { - 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; \ No newline at end of file + 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;