diff --git a/core/modules/user/user.admin.inc b/core/modules/user/user.admin.inc index 3ebfe86..194aec4 100644 --- a/core/modules/user/user.admin.inc +++ b/core/modules/user/user.admin.inc @@ -340,18 +340,6 @@ function user_admin_settings($form, &$form_state) { $form['language'] += translation_entity_enable_widget('user', 'user', $form, $form_state); } - $form['pass_strength'] = array( - '#type' => 'details', - '#title' => t('Password strength indicator'), - ); - - $form['pass_strength']['user_password_strength'] = array( - '#type' => 'checkbox', - '#title' => t('Enable password strength indicator'), - '#default_value' => $config->get('password_strength'), - '#description' => t('Display password strength indicator during account creation and modification.') - ); - // User registration settings. $form['registration_cancellation'] = array( '#type' => 'details', @@ -373,6 +361,12 @@ function user_admin_settings($form, &$form_state) { '#default_value' => $config->get('verify_mail'), '#description' => t('New users will be required to validate their e-mail address prior to logging into the site, and will be assigned a system-generated password. With this setting disabled, users will be logged in immediately upon registering, and may select their own passwords during registration.') ); + $form['registration_cancellation']['user_password_strength'] = array( + '#type' => 'checkbox', + '#title' => t('Enable password strength indicator'), + '#default_value' => $config->get('password_strength'), + '#description' => t('Encourage users to create more secure passwords by displaying a password strength indicator during account creation and modification.') + ); form_load_include($form_state, 'inc', 'user', 'user.pages'); $form['registration_cancellation']['user_cancel_method'] = array( '#type' => 'radios', diff --git a/core/modules/user/user.js b/core/modules/user/user.js index 9a17eed..a9a17b5 100644 --- a/core/modules/user/user.js +++ b/core/modules/user/user.js @@ -23,8 +23,8 @@ Drupal.behaviors.password = { var confirmResult = outerWrapper.find('div.password-confirm'); var confirmChild = confirmResult.find('span'); - // If password strength indicator enabled, add the description box. - if (typeof settings.password.strengthTitle != 'undefined') { + // If the password strength indicator is enabled, add it's markup. + if (settings.password.showStrengthIndicator) { var passwordMeter = '
' + translate.strengthTitle + '
'; confirmInput.parent().after('
'); innerWrapper.prepend(passwordMeter); @@ -32,33 +32,18 @@ Drupal.behaviors.password = { } // Check that password and confirmation inputs match. - var passwordCheckMatch = function () { + var passwordCheckMatch = function (confirmInputVal) { + var success = passwordInput.val() === confirmInputVal; + var confirmClass = success ? 'ok' : 'error'; - if (confirmInput.val()) { - var success = passwordInput.val() === confirmInput.val(); - - // Show the confirm result. - confirmResult.css({ visibility: 'visible' }); - - // Remove the previous styling if any exists. - if (this.confirmClass) { - confirmChild.removeClass(this.confirmClass); - } - - // Fill in the success message and set the class accordingly. - var confirmClass = success ? 'ok' : 'error'; - confirmChild.html(translate['confirm' + (success ? 'Success' : 'Failure')]).addClass(confirmClass); - this.confirmClass = confirmClass; - } - else { - confirmResult.css({ visibility: 'hidden' }); - } + // Fill in the success message and set the class accordingly. + confirmChild.html(translate['confirm' + (success ? 'Success' : 'Failure')]) + .removeClass('ok error').addClass(confirmClass); }; // Check the password strength. var passwordCheck = function () { - // Check if we are actually checking the password strength - if (typeof settings.password.strengthTitle != 'undefined') { + if (settings.password.showStrengthIndicator) { // Evaluate the password strength. var result = Drupal.evaluatePasswordStrength(passwordInput.val(), settings.password); @@ -67,13 +52,8 @@ Drupal.behaviors.password = { passwordDescription.html(result.message); } - // Only show the description box if there is a weakness in the password. - if (result.strength === 100) { - passwordDescription.hide(); - } - else { - passwordDescription.show(); - } + // Only show the description box if a weakness exists in the password. + result.strength === 100 ? passwordDescription.hide() : passwordDescription.show(); // Adjust the length of the strength indicator. innerWrapper.find('.indicator') @@ -83,13 +63,22 @@ Drupal.behaviors.password = { // Update the strength indication text. innerWrapper.find('.password-strength-text').html(result.indicatorText); } - passwordCheckMatch(); + + // Check the value in the confirm input and show results. + if (confirmInput.val()) { + passwordCheckMatch(confirmInput.val()); + confirmResult.css({ visibility: 'visible' }); + } + else { + confirmResult.css({ visibility: 'hidden' }); + } }; - // Monitor keyup and blur events. - // Blur must be used because a mouse paste does not trigger keyup. - passwordInput.keyup(passwordCheck).focus(passwordCheck).blur(passwordCheck); - confirmInput.keyup(passwordCheckMatch).blur(passwordCheckMatch); + // Monitor input events. + $.each([passwordInput, confirmInput], function () { + this.bind('input', passwordCheck); + }); + }); } }; diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 2b6c374..eafe48d 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -2667,6 +2667,7 @@ function user_form_process_password_confirm($element) { global $user; $password_settings += array( + 'showStrengthIndicator' => TRUE, 'strengthTitle' => t('Password strength:'), 'hasWeaknesses' => t('To make your password stronger:'), 'tooShort' => t('Make it at least 6 characters'),