Skip to content

Commit

Permalink
fix: 🐛 validation of confirmation pw after changing pw
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin Spielmann committed Nov 18, 2020
1 parent f7736d2 commit ae4ed60
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
28 changes: 14 additions & 14 deletions src/components/passwordReset/PasswordReset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,32 +116,29 @@ export const PasswordReset = () => {
};

const handleInputOldChange = (event) => {
validateOldPassword(event.target.value);
setOldPasswordErrorMessage('');
setOldPassword(event.target.value);
};

const handleInputNewChange = (event) => {
validateNewPassword(event.target.value);
validateConfirmPassword(confirmPassword, event.target.value);
setNewPassword(event.target.value);
};

const handleInputConfirmChange = (event) => {
validateConfirmPassword(event.target.value);
validateConfirmPassword(event.target.value, newPassword);
setConfirmPassword(event.target.value);
};

const validateOldPassword = (oldPW) => {
setOldPasswordErrorMessage('');
};

const validateNewPassword = (newPw) => {
let passwordStrength = strengthIndicator(newPw);
if (newPw.length >= 1 && passwordStrength < 4) {
const validateNewPassword = (newPassword: string) => {
let passwordStrength = strengthIndicator(newPassword);
if (newPassword.length >= 1 && passwordStrength < 4) {
setNewPasswordSuccessMessage('');
setNewPasswordErrorMessage(
translate('profile.functions.passwordResetInsecure')
);
} else if (newPw.length >= 1) {
} else if (newPassword.length >= 1) {
setNewPasswordSuccessMessage(
translate('profile.functions.passwordResetSecure')
);
Expand All @@ -157,14 +154,17 @@ export const PasswordReset = () => {
!!newPasswordSuccessMessage &&
!!confirmPasswordSuccessMessage;

const validateConfirmPassword = (confirmPw) => {
let passwordFits = inputValuesFit(confirmPw, newPassword);
if (confirmPw.length >= 1 && !passwordFits) {
const validateConfirmPassword = (
confirmPassword: string,
newPassword: string
) => {
let passwordFits = inputValuesFit(confirmPassword, newPassword);
if (confirmPassword.length >= 1 && !passwordFits) {
setConfirmPasswordSuccessMessage('');
setConfirmPasswordErrorMessage(
translate('profile.functions.passwordResetNotSame')
);
} else if (confirmPw.length >= 1) {
} else if (confirmPassword.length >= 1) {
setConfirmPasswordSuccessMessage(
translate('profile.functions.passwordResetSame')
);
Expand Down
10 changes: 7 additions & 3 deletions src/components/registration/Registration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,11 @@ const Registration = () => {
const handlepasswordChange = (event) => {
validatePassword(event.target.value);
setPassword(event.target.value);
validatePasswordConfirmation(passwordConfirmation, event.target.value);
};

const handlePasswordConfirmationChange = (event) => {
validatePasswordConfirmation(event.target.value);
validatePasswordConfirmation(event.target.value, password);
setPasswordConfirmation(event.target.value);
};

Expand Down Expand Up @@ -412,7 +413,7 @@ const Registration = () => {
}
};

const validatePassword = (password) => {
const validatePassword = (password: string) => {
let passwordStrength = strengthIndicator(password);
if (password.length >= 1 && passwordStrength < 4) {
setIsPasswordValid(false);
Expand All @@ -433,7 +434,10 @@ const Registration = () => {
}
};

const validatePasswordConfirmation = (confirmPassword) => {
const validatePasswordConfirmation = (
confirmPassword: string,
password: string
) => {
let passwordFits = inputValuesFit(confirmPassword, password);
if (confirmPassword.length >= 1 && !passwordFits) {
setPasswordConfirmationSuccessMessage('');
Expand Down

0 comments on commit ae4ed60

Please sign in to comment.