Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
fix: password verification, add better feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
KaWaite committed Oct 29, 2021
1 parent 7f4b989 commit bd17257
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/components/molecules/Settings/Account/PasswordModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,17 @@ const PasswordModal: React.FC<Props> = ({
}, [updatePassword, handleClose, password, passwordConfirmation]);

useEffect(() => {
if (password === passwordConfirmation && passwordPolicy?.highSecurity?.test(password)) {
setDisabled(false);
} else {
if (
password !== passwordConfirmation ||
(passwordPolicy?.highSecurity && !passwordPolicy.highSecurity.test(password)) ||
passwordPolicy?.tooShort?.test(password) ||
passwordPolicy?.tooLong?.test(password)
) {
setDisabled(true);
} else {
setDisabled(false);
}
}, [password, passwordConfirmation, passwordPolicy?.highSecurity]);
}, [password, passwordConfirmation, passwordPolicy]);

return (
<Modal
Expand Down Expand Up @@ -152,9 +157,10 @@ const PasswordModal: React.FC<Props> = ({
doesChangeEveryTime
autofocus
color={
passwordPolicy?.whitespace?.test(password) ||
passwordPolicy?.tooLong?.test(password)
? theme.main.danger
: passwordPolicy?.highSecurity?.test(password)
? theme.main.accent
: undefined
}
/>
Expand All @@ -170,6 +176,7 @@ const PasswordModal: React.FC<Props> = ({
value={passwordConfirmation}
onChange={setPasswordConfirmation}
doesChangeEveryTime
color={password === passwordConfirmation ? theme.main.accent : undefined}
/>
</PasswordField>
</div>
Expand Down

0 comments on commit bd17257

Please sign in to comment.