From f47a119474479cdb202c16a4a80891fedafccb4a Mon Sep 17 00:00:00 2001 From: Joel Biddle Date: Tue, 22 Aug 2023 20:20:13 +1000 Subject: [PATCH] fixed breached pwd error messages --- frontend/src/pages/password-reset.tsx | 86 ++++++++++++++++++--------- 1 file changed, 57 insertions(+), 29 deletions(-) diff --git a/frontend/src/pages/password-reset.tsx b/frontend/src/pages/password-reset.tsx index 90fd6be51..6aa3ea275 100644 --- a/frontend/src/pages/password-reset.tsx +++ b/frontend/src/pages/password-reset.tsx @@ -12,7 +12,7 @@ import Button from "@app/components/basic/buttons/Button"; import InputField from "@app/components/basic/InputField"; import passwordCheck from "@app/components/utilities/checks/PasswordCheck"; import Aes256Gcm from "@app/components/utilities/cryptography/aes-256-gcm"; -import { useResetPassword,useVerifyPasswordResetCode } from "@app/hooks/api"; +import { useResetPassword, useVerifyPasswordResetCode } from "@app/hooks/api"; import { getBackupEncryptedPrivateKey } from "@app/hooks/api/auth/queries"; import { deriveArgonKey } from "../components/utilities/cryptography/crypto"; @@ -32,12 +32,13 @@ export default function PasswordReset() { const [passwordErrorTooLong, setPasswordErrorTooLong] = useState(false); const [passwordErrorNumber, setPasswordErrorNumber] = useState(false); const [passwordErrorLowerCase, setPasswordErrorLowerCase] = useState(false); + const [passwordErrorIsBreached, setPasswordErrorIsBreached] = useState(false); const router = useRouter(); const { mutateAsync: verifyPasswordResetCodeMutateAsync } = useVerifyPasswordResetCode(); const { mutateAsync: resetPasswordMutateAsync } = useResetPassword(); - + const parsedUrl = queryString.parse(router.asPath.split("?")[1]); const token = parsedUrl.token as string; const email = (parsedUrl.to as string)?.replace(" ", "+").trim(); @@ -47,7 +48,7 @@ export default function PasswordReset() { e.preventDefault(); try { const result = await getBackupEncryptedPrivateKey({ verificationToken }); - + setPrivateKey( Aes256Gcm.decrypt({ ciphertext: result.encryptedPrivateKey, @@ -57,7 +58,7 @@ export default function PasswordReset() { }) ); setStep(3); - } catch(err) { + } catch (err) { console.error(err); setBackupKeyError(true); } @@ -66,12 +67,13 @@ export default function PasswordReset() { // If everything is correct, reset the password const resetPasswordHandler = async (e: FormEvent) => { e.preventDefault(); - const errorCheck = passwordCheck({ + const errorCheck = await passwordCheck({ password: newPassword, setPasswordErrorTooShort, setPasswordErrorTooLong, setPasswordErrorNumber, setPasswordErrorLowerCase, + setPasswordErrorIsBreached, errorCheck: false }); @@ -129,10 +131,10 @@ export default function PasswordReset() { verifier: result.verifier, verificationToken }); - + router.push("/login"); - setLoading(false) + setLoading(false); }); } ); @@ -171,13 +173,17 @@ export default function PasswordReset() { // Input backup key const stepInputBackupKey = ( -
+

Enter your backup key

-
-

- You can find it in your emergency kit. You had to download the emergency kit during signup. +

+

+ You can find it in your emergency kit. You had to download the emergency kit during + signup.

@@ -194,12 +200,7 @@ export default function PasswordReset() {
-
@@ -207,7 +208,10 @@ export default function PasswordReset() { // Enter new password const stepEnterNewPassword = ( -
+

Enter new password

@@ -227,18 +231,29 @@ export default function PasswordReset() { setPasswordErrorTooLong, setPasswordErrorNumber, setPasswordErrorLowerCase, + setPasswordErrorIsBreached, errorCheck: false }); }} type="password" value={newPassword} isRequired - error={passwordErrorTooShort && passwordErrorTooLong && passwordErrorLowerCase && passwordErrorNumber} + error={ + passwordErrorTooShort && + passwordErrorTooLong && + passwordErrorNumber && + passwordErrorLowerCase && + passwordErrorIsBreached + } autoComplete="new-password" id="new-password" />
- {passwordErrorTooShort || passwordErrorTooLong || passwordErrorLowerCase || passwordErrorNumber ? ( + {passwordErrorTooShort || + passwordErrorTooLong || + passwordErrorNumber || + passwordErrorLowerCase || + passwordErrorIsBreached ? (
Password should contain:
@@ -261,6 +276,16 @@ export default function PasswordReset() { at most 100 characters
+
+ {passwordErrorNumber ? ( + + ) : ( + + )} +
+ at least 1 number +
+
{passwordErrorLowerCase ? ( @@ -272,15 +297,18 @@ export default function PasswordReset() { > at least 1 lowercase character
- -
- {passwordErrorNumber ? ( - - ) : ( - - )} -
- at least 1 number +
+ {passwordErrorIsBreached ? ( + + ) : ( + + )} +
+ The password you provided is in a list of passwords commonly used on other websites. + Please try again with a stronger password. +