From 58280acaf8b411dd94ab2fc39785f35be8ea1ed0 Mon Sep 17 00:00:00 2001 From: Alisson Oldoni Date: Wed, 21 Feb 2018 13:47:52 +1100 Subject: [PATCH 1/2] Fix bug Magento 2.2.2 password reset strength meter #13429 --- .../web/js/password-strength-indicator.js | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Customer/view/frontend/web/js/password-strength-indicator.js b/app/code/Magento/Customer/view/frontend/web/js/password-strength-indicator.js index cb38535eb808d..f2d03ca0a465a 100644 --- a/app/code/Magento/Customer/view/frontend/web/js/password-strength-indicator.js +++ b/app/code/Magento/Customer/view/frontend/web/js/password-strength-indicator.js @@ -31,6 +31,11 @@ define([ this.options.cache.input = $(this.options.passwordSelector, this.element); this.options.cache.meter = $(this.options.passwordStrengthMeterSelector, this.element); this.options.cache.label = $(this.options.passwordStrengthMeterLabelSelector, this.element); + + // We need to look outside the module for backward compatibility, since someone can already use the module. + // @todo Narrow this selector in 2.3 so it doesn't accidentally finds the the email field from the newsletter + // email field or any other "email" field. + this.options.cache.email = $(this.options.formSelector).find(this.options.emailSelector); this._bind(); }, @@ -60,8 +65,20 @@ define([ // Display score is based on combination of whether password is empty, valid, and zxcvbn strength if (isEmpty) { displayScore = 0; - } else if (!isValid) { - displayScore = 1; + } else { + this.options.cache.input.rules('add', { + 'password-not-equal-to-user-name': this.options.cache.email.val() + }); + + // We should only perform this check in case there is an email field on screen + if (this.options.cache.email.length && + password.toLowerCase() === this.options.cache.email.val().toLowerCase()) { + displayScore = 1; + } else { + isValid = $.validator.validateSingleElement(this.options.cache.input); + zxcvbnScore = zxcvbn(password).score; + displayScore = isValid ? zxcvbnScore : 1; + } } // Update label From 74e3a12de6c3b7e9cda12972b2c850eb41416cad Mon Sep 17 00:00:00 2001 From: Alisson Oldoni Date: Wed, 21 Feb 2018 14:22:21 +1100 Subject: [PATCH 2/2] Fixing line 34 length as per jslint configuration --- .../view/frontend/web/js/password-strength-indicator.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Customer/view/frontend/web/js/password-strength-indicator.js b/app/code/Magento/Customer/view/frontend/web/js/password-strength-indicator.js index f2d03ca0a465a..a4c532b324dd5 100644 --- a/app/code/Magento/Customer/view/frontend/web/js/password-strength-indicator.js +++ b/app/code/Magento/Customer/view/frontend/web/js/password-strength-indicator.js @@ -33,8 +33,8 @@ define([ this.options.cache.label = $(this.options.passwordStrengthMeterLabelSelector, this.element); // We need to look outside the module for backward compatibility, since someone can already use the module. - // @todo Narrow this selector in 2.3 so it doesn't accidentally finds the the email field from the newsletter - // email field or any other "email" field. + // @todo Narrow this selector in 2.3 so it doesn't accidentally finds the the email field from the + // newsletter email field or any other "email" field. this.options.cache.email = $(this.options.formSelector).find(this.options.emailSelector); this._bind(); },