Skip to content

Commit

Permalink
No need to checkPassword since field validation already covers this
Browse files Browse the repository at this point in the history
See #10615 (comment)

Both of the error cases are covered by the logic in `verifyFieldsBeforeSubmit()` just above
and there is no way `checkPassword` would ever throw one of these errors since they are
already valid by the time it reaches here.
  • Loading branch information
MadLittleMods committed Apr 15, 2023
1 parent c62c6c9 commit 7786dd1
Showing 1 changed file with 1 addition and 23 deletions.
24 changes: 1 addition & 23 deletions src/components/views/settings/ChangePassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,22 +205,6 @@ export default class ChangePassword extends React.Component<IProps, IState> {
});
}

/**
* Checks the `newPass` and throws an error if it is unacceptable.
* @param oldPass The old password
* @param newPass The new password that the user is trying to be set
* @param confirmPass The confirmation password where the user types the `newPass`
* again for confirmation and should match the `newPass` before we accept their new
* password.
*/
private checkPassword(oldPass: string, newPass: string, confirmPass: string): void {
if (newPass !== confirmPass) {
throw new UserFriendlyError("New passwords don't match");
} else if (!newPass || newPass.length === 0) {
throw new UserFriendlyError("Passwords can't be empty");
}
}

private optionallySetEmail(): Promise<boolean> {
// Ask for an email otherwise the user has no way to reset their password
const modal = Modal.createDialog(SetEmailDialog, {
Expand Down Expand Up @@ -319,13 +303,7 @@ export default class ChangePassword extends React.Component<IProps, IState> {

const oldPassword = this.state.oldPassword;
const newPassword = this.state.newPassword;
const confirmPassword = this.state.newPasswordConfirm;
try {
this.checkPassword(oldPassword, newPassword, confirmPassword);
return this.onChangePassword(oldPassword, newPassword);
} catch (err) {
this.props.onError(err);
}
return this.onChangePassword(oldPassword, newPassword);
};

private async verifyFieldsBeforeSubmit(): Promise<boolean> {
Expand Down

0 comments on commit 7786dd1

Please sign in to comment.