diff --git a/core/modules/user/user.js b/core/modules/user/user.js index 36b0501..3c5a4ae 100644 --- a/core/modules/user/user.js +++ b/core/modules/user/user.js @@ -53,11 +53,12 @@ Drupal.behaviors.password = { } // Only show the description box if a weakness exists in the password. - passwordDescription.toggle(result.strength !== 100); + passwordDescription.toggle(result.strength !== 4); - // Adjust the length of the strength indicator. + // Adjust the length of the strength indicator, the zxcvbn library + // will return a strength indicator from 0 (weak) to 4 (strong). innerWrapper.find('.indicator') - .css('width', result.strength + '%') + .css('width', ((result.strength * 20) + 20) + '%') .css('background-color', result.indicatorColor); // Update the strength indication text. @@ -87,7 +88,7 @@ Drupal.behaviors.password = { * Returns the estimated strength and the relevant output message. */ Drupal.evaluatePasswordStrength = function (password, translate) { - var indicatorText, indicatorColor, weaknesses = 0, strength = 100, msg = []; + var indicatorText, indicatorColor, msg = []; var hasLowercase = /[a-z]+/.test(password); var hasUppercase = /[A-Z]+/.test(password); @@ -107,6 +108,12 @@ Drupal.evaluatePasswordStrength = function (password, translate) { var result = zxcvbn(password, blacklist); // Give the user some suggestions to make the password stronger. + if (result.match_sequence.length <= 1) { + msg.push(translate.basedOnADictionaryWord); + } + else if (result.match_sequence.length <= 2) { + msg.push(translate.addWords); + } if (password.length < 6) { msg.push(translate.tooShort); } @@ -134,20 +141,16 @@ Drupal.evaluatePasswordStrength = function (password, translate) { case 0 : indicatorText = translate.weak; indicatorColor = '#bb5555'; - strength = 20; break; case 1 : indicatorText = translate.fair; indicatorColor = '#bbbb55'; - strength = 40; break; case 2 : indicatorText = translate.good; indicatorColor = '#4863a0'; - strength = 60; break; case 3 : - strength = 80; case 4 : indicatorText = translate.strong; indicatorColor = '#47c965'; @@ -156,7 +159,7 @@ Drupal.evaluatePasswordStrength = function (password, translate) { // Assemble the final message. msg = translate.hasWeaknesses + ''; - return { strength: strength, message: msg, indicatorText: indicatorText, indicatorColor: indicatorColor }; + return { strength: result.score, message: msg, indicatorText: indicatorText, indicatorColor: indicatorColor }; }; /** diff --git a/core/modules/user/user.module b/core/modules/user/user.module index c9a22bb..4bde894 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -1712,6 +1712,8 @@ function user_form_process_password_confirm($element) { $password_settings += array( 'strengthTitle' => t('Password strength:'), 'hasWeaknesses' => t('To make your password stronger:'), + 'basedOnADictionaryWord' => t('Do not base the password on a dictionary word'), + 'addWords' => t('Add words'), 'tooShort' => t('Make it at least 6 characters'), 'addLowerCase' => t('Add lowercase letters'), 'addUpperCase' => t('Add uppercase letters'),