Skip to content

Commit 46f0584

Browse files
author
Dale Sikkema
committed
MAGETWO-51815: Invalid work of Password Strength Validator on "Create Customer" Storefront page
1 parent ee61591 commit 46f0584

File tree

4 files changed

+64
-25
lines changed

4 files changed

+64
-25
lines changed

app/code/Magento/Customer/i18n/en_US.csv

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,3 +517,9 @@ Addresses,Addresses
517517
"Password forgotten","Password forgotten"
518518
"My Dashboard","My Dashboard"
519519
"You are signed out","You are signed out"
520+
"No Password","No Password"
521+
"Weak","Weak"
522+
"Medium","Medium"
523+
"Strong","Strong"
524+
"Very Strong","Very Strong"
525+

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

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ define([
4848
*/
4949
_calculateStrength: function () {
5050
var password = this._getPassword(),
51+
isEmpty = password.length === 0,
5152
score = zxcvbn(password).score,
52-
className = this._getClassName(score);
53+
className = this._getClassName(score, isEmpty);
5354

54-
this._displayStrength(className, score);
55+
this._displayStrength(className, score, isEmpty);
5556
//update error messages
5657
$.validator.validateSingleElement(this.element.find('input[type="password"]'));
5758
},
@@ -60,35 +61,37 @@ define([
6061
* Display strength
6162
* @param {String} className
6263
* @param {Number} score
64+
* @param {Boolean} isEmpty
6365
* @private
6466
*/
65-
_displayStrength: function (className, score) {
67+
_displayStrength: function (className, score, isEmpty) {
6668
var strengthContainer = this.element.find('#' + this.options.passwordStrengthMeterId),
6769
strengthLabel = '';
6870

6971
strengthContainer.removeClass();
7072
strengthContainer.addClass(className);
7173

72-
switch (score) {
73-
case 1:
74-
strengthLabel = $t('Weak');
75-
break;
76-
77-
case 2:
78-
strengthLabel = $t('Medium');
79-
break;
80-
81-
case 3:
82-
strengthLabel = $t('Strong');
83-
break;
84-
85-
case 4:
86-
strengthLabel = $t('Very Strong');
87-
break;
88-
89-
case 0:
90-
default:
91-
strengthLabel = $t('No password');
74+
if (isEmpty) {
75+
strengthLabel = $t('No Password');
76+
} else {
77+
switch (score) {
78+
case 0:
79+
case 1:
80+
strengthLabel = $t('Weak');
81+
break;
82+
83+
case 2:
84+
strengthLabel = $t('Medium');
85+
break;
86+
87+
case 3:
88+
strengthLabel = $t('Strong');
89+
break;
90+
91+
case 4:
92+
strengthLabel = $t('Very Strong');
93+
break;
94+
}
9295
}
9396

9497
this.element.find('#' + this.options.passwordStrengthMeterLabelId).text(strengthLabel);
@@ -106,11 +109,13 @@ define([
106109
/**
107110
* Get class name for score
108111
* @param {int} score
112+
* @param {Boolean} isEmpty
109113
* @returns {String}
110114
* @private
111115
*/
112-
_getClassName: function (score) {
113-
return this.options.defaultClassName + score;
116+
_getClassName: function (score, isEmpty) {
117+
var suffix = isEmpty ? 'no-pwd' : score;
118+
return this.options.defaultClassName + suffix;
114119
}
115120
});
116121

app/design/frontend/Magento/blank/Magento_Customer/web/css/source/_module.less

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,20 @@
271271
z-index: -1;
272272
}
273273

274+
.password-strength-meter-no-pwd & {
275+
&:before {
276+
background-color: @password-strength-color__default;
277+
width: 100%;
278+
}
279+
}
280+
281+
.password-strength-meter-0 & {
282+
&:before {
283+
background-color: @password-strength-color__weak;
284+
width: 25%;
285+
}
286+
}
287+
274288
.password-strength-meter-1 & {
275289
&:before {
276290
background-color: @password-strength-color__weak;

app/design/frontend/Magento/luma/Magento_Customer/web/css/source/_module.less

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,20 @@
249249
z-index: -1;
250250
}
251251

252+
.password-strength-meter-no-pwd & {
253+
&:before {
254+
background-color: @password-strength-color__default;
255+
width: 100%;
256+
}
257+
}
258+
259+
.password-strength-meter-0 & {
260+
&:before {
261+
background-color: @password-strength-color__weak;
262+
width: 25%;
263+
}
264+
}
265+
252266
.password-strength-meter-1 & {
253267
&:before {
254268
background-color: @password-strength-color__weak;

0 commit comments

Comments
 (0)