Issue #331893 by mgifford, nigel, Xano, Everett Zufelt, nod_: Added colouring (and description) to password checker.

8.0.x
catch 2012-04-02 12:03:17 +09:00
parent 588a7e1e4f
commit a3d299b8b4
1 changed files with 7 additions and 2 deletions

View File

@ -48,6 +48,7 @@ Drupal.behaviors.password = {
// Adjust the length of the strength indicator. // Adjust the length of the strength indicator.
$(innerWrapper).find('.indicator').css('width', result.strength + '%'); $(innerWrapper).find('.indicator').css('width', result.strength + '%');
$(innerWrapper).find('.indicator').css('background-color', result.indicatorColor);
// Update the strength indication text. // Update the strength indication text.
$(innerWrapper).find('.password-strength-text').html(result.indicatorText); $(innerWrapper).find('.password-strength-text').html(result.indicatorText);
@ -93,7 +94,7 @@ Drupal.behaviors.password = {
* Returns the estimated strength and the relevant output message. * Returns the estimated strength and the relevant output message.
*/ */
Drupal.evaluatePasswordStrength = function (password, translate) { Drupal.evaluatePasswordStrength = function (password, translate) {
var weaknesses = 0, strength = 100, msg = []; var indicatorText, indicatorColor, weaknesses = 0, strength = 100, msg = [];
var hasLowercase = password.match(/[a-z]+/); var hasLowercase = password.match(/[a-z]+/);
var hasUppercase = password.match(/[A-Z]+/); var hasUppercase = password.match(/[A-Z]+/);
@ -158,17 +159,21 @@ Drupal.evaluatePasswordStrength = function (password, translate) {
// Based on the strength, work out what text should be shown by the password strength meter. // Based on the strength, work out what text should be shown by the password strength meter.
if (strength < 60) { if (strength < 60) {
indicatorText = translate.weak; indicatorText = translate.weak;
indicatorColor = '#bb5555';
} else if (strength < 70) { } else if (strength < 70) {
indicatorText = translate.fair; indicatorText = translate.fair;
indicatorColor = '#bbbb55';
} else if (strength < 80) { } else if (strength < 80) {
indicatorText = translate.good; indicatorText = translate.good;
indicatorColor = '#4863a0';
} else if (strength <= 100) { } else if (strength <= 100) {
indicatorText = translate.strong; indicatorText = translate.strong;
indicatorColor = '#47c965';
} }
// Assemble the final message. // Assemble the final message.
msg = translate.hasWeaknesses + '<ul><li>' + msg.join('</li><li>') + '</li></ul>'; msg = translate.hasWeaknesses + '<ul><li>' + msg.join('</li><li>') + '</li></ul>';
return { strength: strength, message: msg, indicatorText: indicatorText }; return { strength: strength, message: msg, indicatorText: indicatorText, indicatorColor: indicatorColor };
}; };