From 6dcb0eb5ccc784a204d0879b9fe025038ac0d19b Mon Sep 17 00:00:00 2001 From: Nicholas Date: Thu, 29 Feb 2024 19:20:58 -0500 Subject: [PATCH] added validation for strong passwords. --- compass/app/auth/newPassword/page.tsx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/compass/app/auth/newPassword/page.tsx b/compass/app/auth/newPassword/page.tsx index a49f566..cdf55d8 100644 --- a/compass/app/auth/newPassword/page.tsx +++ b/compass/app/auth/newPassword/page.tsx @@ -15,15 +15,21 @@ function isStrongPassword(password: string): boolean { export default function Page() { const [newPassword, setNewPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); + const [valid, setValid] = useState(false); + const [matching, setMatching] = useState(false); const [isButtonDisabled, setIsButtonDisabled] = useState(true); + useEffect(() => { + setValid(isStrongPassword(newPassword)) + setMatching(newPassword === confirmPassword) + }, [newPassword, confirmPassword]) useEffect(() => { - console.log('newPassword',newPassword) - console.log('confirmPassword',confirmPassword) - setIsButtonDisabled(newPassword === '' || confirmPassword === '' || newPassword !== confirmPassword); + setIsButtonDisabled(newPassword === '' || confirmPassword === '' || !matching || !valid); + console.log(matching) + console.log(valid) console.log('newPasswordDisabledTest',isButtonDisabled) - }, [newPassword, confirmPassword]); + }, [matching, valid]); return (