Skip to content

Commit 7d1192d

Browse files
MAGETWO-51815: Invalid work of Password Strength Validator on "Create Customer" Storefront page
1 parent 8b4d93f commit 7d1192d

File tree

3 files changed

+53
-51
lines changed

3 files changed

+53
-51
lines changed

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

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -53,45 +53,50 @@ define([
5353
_calculateStrength: function () {
5454
var password = this._getPassword(),
5555
isEmpty = password.length === 0,
56-
score = zxcvbn(password).score,
57-
className = this._getClassName(score, isEmpty);
56+
zxcvbnScore = zxcvbn(password).score,
57+
isValid = $.validator.validateSingleElement(this.options.cache.input),
58+
displayScore = zxcvbnScore;
5859

59-
this._displayStrength(className, score, isEmpty);
60-
//update error messages
61-
$.validator.validateSingleElement(this.options.cache.input);
60+
// Display score is based on combination of whether password is empty, valid, and zxcvbn strength
61+
if (isEmpty) {
62+
displayScore = 0;
63+
} else if (!isValid) {
64+
displayScore = 1;
65+
}
66+
67+
// Update label
68+
this._displayStrength(displayScore);
6269
},
6370

6471
/**
6572
* Display strength
66-
* @param {String} className
67-
* @param {Number} score
68-
* @param {Boolean} isEmpty
73+
* @param {Number} displayScore
6974
* @private
7075
*/
71-
_displayStrength: function (className, score, isEmpty) {
72-
var strengthLabel = '';
73-
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-
}
76+
_displayStrength: function (displayScore) {
77+
var strengthLabel = '',
78+
className = this._getClassName(displayScore);
79+
80+
switch (displayScore) {
81+
case 0:
82+
strengthLabel = $t('No Password');
83+
break;
84+
85+
case 1:
86+
strengthLabel = $t('Weak');
87+
break;
88+
89+
case 2:
90+
strengthLabel = $t('Medium');
91+
break;
92+
93+
case 3:
94+
strengthLabel = $t('Strong');
95+
break;
96+
97+
case 4:
98+
strengthLabel = $t('Very Strong');
99+
break;
95100
}
96101

97102
this.options.cache.meter
@@ -111,13 +116,12 @@ define([
111116

112117
/**
113118
* Get class name for score
114-
* @param {int} score
115-
* @param {Boolean} isEmpty
119+
* @param {int} displayScore
116120
* @returns {String}
117121
* @private
118122
*/
119-
_getClassName: function (score, isEmpty) {
120-
return this.options.defaultClassName + (isEmpty ? 'no-pwd' : score);
123+
_getClassName: function (displayScore) {
124+
return this.options.defaultClassName + displayScore;
121125
}
122126
});
123127

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,14 +271,13 @@
271271
z-index: -1;
272272
}
273273

274-
.password-strength-meter-no-pwd & {
274+
.password-strength-meter-0 & {
275275
&:before {
276276
background-color: @_password-default;
277277
width: 100%;
278278
}
279279
}
280280

281-
.password-strength-meter-0 &,
282281
.password-strength-meter-1 & {
283282
&:before {
284283
background-color: @_password-weak;

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
@account-table-border-bottom-color: @color-gray-middle1;
88
@account-table-action-delete: @color-red12;
99

10-
@password-default: @color-gray-light01;
11-
@password-weak: #ffafae;
12-
@password-medium: #ffd6b3;
13-
@password-strong: #c5eeac;
14-
@password-very-strong: #81b562;
10+
@_password-default: @color-gray-light01;
11+
@_password-weak: #ffafae;
12+
@_password-medium: #ffd6b3;
13+
@_password-strong: #c5eeac;
14+
@_password-very-strong: #81b562;
1515

1616
//
1717
// Common
@@ -233,7 +233,7 @@
233233
}
234234

235235
.password-strength-meter {
236-
background-color: @password-default;
236+
background-color: @_password-default;
237237
height: @form-element-input__height;
238238
line-height: @form-element-input__height;
239239
padding: @form-element-input__padding;
@@ -249,38 +249,37 @@
249249
z-index: -1;
250250
}
251251

252-
.password-strength-meter-no-pwd & {
252+
.password-strength-meter-0 & {
253253
&:before {
254-
background-color: @password-default;
254+
background-color: @_password-default;
255255
width: 100%;
256256
}
257257
}
258258

259-
.password-strength-meter-0 &,
260259
.password-strength-meter-1 & {
261260
&:before {
262-
background-color: @password-weak;
261+
background-color: @_password-weak;
263262
width: 25%;
264263
}
265264
}
266265

267266
.password-strength-meter-2 & {
268267
&:before {
269-
background-color: @password-medium;
268+
background-color: @_password-medium;
270269
width: 50%;
271270
}
272271
}
273272

274273
.password-strength-meter-3 & {
275274
&:before {
276-
background-color: @password-strong;
275+
background-color: @_password-strong;
277276
width: 75%;
278277
}
279278
}
280279

281280
.password-strength-meter-4 & {
282281
&:before {
283-
background-color: @password-very-strong;
282+
background-color: @_password-very-strong;
284283
width: 100%;
285284
}
286285
}

0 commit comments

Comments
 (0)