Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 4d72af7

Browse files
authored
Merge pull request #5744 from panoschal/forgot-password-validation
Require strong password in forgot password form
2 parents cd39474 + 901d5a8 commit 4d72af7

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

src/components/structures/auth/ForgotPassword.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ limitations under the License.
1818

1919
import React from 'react';
2020
import PropTypes from 'prop-types';
21-
import { _t } from '../../../languageHandler';
21+
import { _t, _td } from '../../../languageHandler';
2222
import * as sdk from '../../../index';
2323
import Modal from "../../../Modal";
2424
import PasswordReset from "../../../PasswordReset";
@@ -27,7 +27,9 @@ import classNames from 'classnames';
2727
import AuthPage from "../../views/auth/AuthPage";
2828
import CountlyAnalytics from "../../../CountlyAnalytics";
2929
import ServerPicker from "../../views/elements/ServerPicker";
30+
import PassphraseField from '../../views/auth/PassphraseField';
3031
import {replaceableComponent} from "../../../utils/replaceableComponent";
32+
import { PASSWORD_MIN_SCORE } from '../../views/auth/RegistrationForm';
3133

3234
// Phases
3335
// Show the forgot password inputs
@@ -137,10 +139,14 @@ export default class ForgotPassword extends React.Component {
137139
// refresh the server errors, just in case the server came back online
138140
await this._checkServerLiveliness(this.props.serverConfig);
139141

142+
await this['password_field'].validate({ allowEmpty: false });
143+
140144
if (!this.state.email) {
141145
this.showErrorDialog(_t('The email address linked to your account must be entered.'));
142146
} else if (!this.state.password || !this.state.password2) {
143147
this.showErrorDialog(_t('A new password must be entered.'));
148+
} else if (!this.state.passwordFieldValid) {
149+
this.showErrorDialog(_t('Please choose a strong password'));
144150
} else if (this.state.password !== this.state.password2) {
145151
this.showErrorDialog(_t('New passwords must match each other.'));
146152
} else {
@@ -186,6 +192,12 @@ export default class ForgotPassword extends React.Component {
186192
});
187193
}
188194

195+
onPasswordValidate(result) {
196+
this.setState({
197+
passwordFieldValid: result.valid,
198+
});
199+
}
200+
189201
renderForgot() {
190202
const Field = sdk.getComponent('elements.Field');
191203

@@ -230,12 +242,15 @@ export default class ForgotPassword extends React.Component {
230242
/>
231243
</div>
232244
<div className="mx_AuthBody_fieldRow">
233-
<Field
245+
<PassphraseField
234246
name="reset_password"
235247
type="password"
236-
label={_t('New Password')}
248+
label={_td('New Password')}
237249
value={this.state.password}
250+
minScore={PASSWORD_MIN_SCORE}
238251
onChange={this.onInputChanged.bind(this, "password")}
252+
fieldRef={field => this['password_field'] = field}
253+
onValidate={(result) => this.onPasswordValidate(result)}
239254
onFocus={() => CountlyAnalytics.instance.track("onboarding_forgot_password_newPassword_focus")}
240255
onBlur={() => CountlyAnalytics.instance.track("onboarding_forgot_password_newPassword_blur")}
241256
autoComplete="new-password"

src/components/views/auth/RegistrationForm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ enum RegistrationField {
4040
PasswordConfirm = "field_password_confirm",
4141
}
4242

43-
const PASSWORD_MIN_SCORE = 3; // safely unguessable: moderate protection from offline slow-hash scenario.
43+
export const PASSWORD_MIN_SCORE = 3; // safely unguessable: moderate protection from offline slow-hash scenario.
4444

4545
interface IProps {
4646
// Values pre-filled in the input boxes when the component loads

src/components/views/settings/ChangePassword.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,12 @@ import Modal from "../../../Modal";
2828
import PassphraseField from "../auth/PassphraseField";
2929
import CountlyAnalytics from "../../../CountlyAnalytics";
3030
import {replaceableComponent} from "../../../utils/replaceableComponent";
31+
import { PASSWORD_MIN_SCORE } from '../auth/RegistrationForm';
3132

3233
const FIELD_OLD_PASSWORD = 'field_old_password';
3334
const FIELD_NEW_PASSWORD = 'field_new_password';
3435
const FIELD_NEW_PASSWORD_CONFIRM = 'field_new_password_confirm';
3536

36-
const PASSWORD_MIN_SCORE = 3; // safely unguessable: moderate protection from offline slow-hash scenario.
37-
3837
@replaceableComponent("views.settings.ChangePassword")
3938
export default class ChangePassword extends React.Component {
4039
static propTypes = {

src/i18n/strings/en_EN.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2700,6 +2700,7 @@
27002700
"Failed to send email": "Failed to send email",
27012701
"The email address linked to your account must be entered.": "The email address linked to your account must be entered.",
27022702
"A new password must be entered.": "A new password must be entered.",
2703+
"Please choose a strong password": "Please choose a strong password",
27032704
"New passwords must match each other.": "New passwords must match each other.",
27042705
"Changing your password will reset any end-to-end encryption keys on all of your sessions, making encrypted chat history unreadable. Set up Key Backup or export your room keys from another session before resetting your password.": "Changing your password will reset any end-to-end encryption keys on all of your sessions, making encrypted chat history unreadable. Set up Key Backup or export your room keys from another session before resetting your password.",
27052706
"New Password": "New Password",

0 commit comments

Comments
 (0)