Skip to content

Commit 242b359

Browse files
ENGCOM-2653: [Backport] Fix bug Magento 2.2.2 password reset strength meter #13429 #17290
- Merge Pull Request #17290 from jignesh-baldha/magento2:2.1-develop-PR-port-13761 - Merged commits: 1. 58280ac 2. 74e3a12
2 parents b49447b + 74e3a12 commit 242b359

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

app/code/Magento/Customer/view/frontend/web/js/password-strength-indicator.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ define([
3131
this.options.cache.input = $(this.options.passwordSelector, this.element);
3232
this.options.cache.meter = $(this.options.passwordStrengthMeterSelector, this.element);
3333
this.options.cache.label = $(this.options.passwordStrengthMeterLabelSelector, this.element);
34+
35+
// We need to look outside the module for backward compatibility, since someone can already use the module.
36+
// @todo Narrow this selector in 2.3 so it doesn't accidentally finds the the email field from the
37+
// newsletter email field or any other "email" field.
38+
this.options.cache.email = $(this.options.formSelector).find(this.options.emailSelector);
3439
this._bind();
3540
},
3641

@@ -60,8 +65,20 @@ define([
6065
// Display score is based on combination of whether password is empty, valid, and zxcvbn strength
6166
if (isEmpty) {
6267
displayScore = 0;
63-
} else if (!isValid) {
64-
displayScore = 1;
68+
} else {
69+
this.options.cache.input.rules('add', {
70+
'password-not-equal-to-user-name': this.options.cache.email.val()
71+
});
72+
73+
// We should only perform this check in case there is an email field on screen
74+
if (this.options.cache.email.length &&
75+
password.toLowerCase() === this.options.cache.email.val().toLowerCase()) {
76+
displayScore = 1;
77+
} else {
78+
isValid = $.validator.validateSingleElement(this.options.cache.input);
79+
zxcvbnScore = zxcvbn(password).score;
80+
displayScore = isValid ? zxcvbnScore : 1;
81+
}
6582
}
6683

6784
// Update label

0 commit comments

Comments
 (0)