2015-06-05 20:17:55 +00:00
/ * *
2017-05-19 22:12:53 +00:00
* DO NOT EDIT THIS FILE .
* See the following change record for more information ,
2017-05-23 14:30:14 +00:00
* https : //www.drupal.org/node/2815083
2017-05-19 22:12:53 +00:00
* @ preserve
* * /
2015-06-05 20:17:55 +00:00
2020-09-29 23:44:28 +00:00
( function ( $ , Drupal ) {
Drupal . user = {
password : {
css : {
passwordParent : 'password-parent' ,
passwordsMatch : 'ok' ,
passwordsNotMatch : 'error' ,
passwordWeak : 'is-weak' ,
passwordFair : 'is-fair' ,
passwordGood : 'is-good' ,
passwordStrong : 'is-strong' ,
widgetInitial : '' ,
passwordEmpty : '' ,
passwordFilled : '' ,
confirmEmpty : '' ,
confirmFilled : ''
}
}
} ;
2014-01-27 21:41:32 +00:00
Drupal . behaviors . password = {
2017-05-19 22:12:53 +00:00
attach : function attach ( context , settings ) {
2020-09-29 23:44:28 +00:00
var cssClasses = Drupal . user . password . css ;
$ ( context ) . find ( 'input.js-password-field' ) . once ( 'password' ) . each ( function ( index , value ) {
var $mainInput = $ ( value ) ;
var $mainInputParent = $mainInput . parent ( ) . addClass ( cssClasses . passwordParent ) ;
var $passwordWidget = $mainInput . closest ( '.js-form-type-password-confirm' ) ;
var $confirmInput = $passwordWidget . find ( 'input.js-password-confirm' ) ;
var $passwordConfirmMessage = $ ( Drupal . theme ( 'passwordConfirmMessage' , settings . password ) ) ;
var $passwordMatchStatus = $passwordConfirmMessage . find ( '[data-drupal-selector="password-match-status-text"]' ) . first ( ) ;
if ( $passwordMatchStatus . length === 0 ) {
$passwordMatchStatus = $passwordConfirmMessage . find ( 'span' ) . first ( ) ;
Drupal . deprecationError ( {
message : 'Returning <span> without data-drupal-selector="password-match-status-text" attribute is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. See https://www.drupal.org/node/3152101'
} ) ;
}
var $confirmInputParent = $confirmInput . parent ( ) . addClass ( 'confirm-parent' ) . append ( $passwordConfirmMessage ) ;
var passwordStrengthBarClassesToRemove = [ cssClasses . passwordWeak || '' , cssClasses . passwordFair || '' , cssClasses . passwordGood || '' , cssClasses . passwordStrong || '' ] . join ( ' ' ) . trim ( ) ;
var confirmTextWrapperClassesToRemove = [ cssClasses . passwordsMatch || '' , cssClasses . passwordsNotMatch || '' ] . join ( ' ' ) . trim ( ) ;
var widgetClassesToRemove = [ cssClasses . widgetInitial || '' , cssClasses . passwordEmpty || '' , cssClasses . passwordFilled || '' , cssClasses . confirmEmpty || '' , cssClasses . confirmFilled || '' ] . join ( ' ' ) . trim ( ) ;
var password = { } ;
2014-01-27 21:41:32 +00:00
if ( settings . password . showStrengthIndicator ) {
2020-09-29 23:44:28 +00:00
var $passwordStrength = $ ( Drupal . theme ( 'passwordStrength' , settings . password ) ) ;
password . $strengthBar = $passwordStrength . find ( '[data-drupal-selector="password-strength-indicator"]' ) . first ( ) ;
if ( password . $strengthBar . length === 0 ) {
password . $strengthBar = $passwordStrength . find ( '.js-password-strength__indicator' ) . first ( ) ;
Drupal . deprecationError ( {
message : 'The js-password-strength__indicator class is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Replace js-password-strength__indicator with a data-drupal-selector="password-strength-indicator" attribute. See https://www.drupal.org/node/3152101'
} ) ;
}
password . $strengthTextWrapper = $passwordStrength . find ( '[data-drupal-selector="password-strength-text"]' ) . first ( ) ;
if ( password . $strengthTextWrapper . length === 0 ) {
password . $strengthTextWrapper = $passwordStrength . find ( '.js-password-strength__text' ) . first ( ) ;
Drupal . deprecationError ( {
message : 'The js-password-strength__text class is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Replace js-password-strength__text with a data-drupal-selector="password-strength-text" attribute. See https://www.drupal.org/node/3152101'
} ) ;
}
password . $suggestions = $ ( Drupal . theme ( 'passwordSuggestions' , settings . password , [ ] ) ) ;
password . $suggestions . hide ( ) ;
$mainInputParent . append ( $passwordStrength ) ;
$confirmInputParent . after ( password . $suggestions ) ;
2014-01-27 21:41:32 +00:00
}
2010-02-16 01:05:52 +00:00
2020-09-29 23:44:28 +00:00
var addWidgetClasses = function addWidgetClasses ( ) {
$passwordWidget . addClass ( $mainInput . val ( ) ? cssClasses . passwordFilled : cssClasses . passwordEmpty ) . addClass ( $confirmInput . val ( ) ? cssClasses . confirmFilled : cssClasses . confirmEmpty ) ;
} ;
2017-05-19 22:12:53 +00:00
var passwordCheckMatch = function passwordCheckMatch ( confirmInputVal ) {
2020-09-29 23:44:28 +00:00
var passwordsAreMatching = $mainInput . val ( ) === confirmInputVal ;
var confirmClass = passwordsAreMatching ? cssClasses . passwordsMatch : cssClasses . passwordsNotMatch ;
var confirmMessage = passwordsAreMatching ? settings . password . confirmSuccess : settings . password . confirmFailure ;
if ( ! $passwordMatchStatus . hasClass ( confirmClass ) || ! $passwordMatchStatus . html ( ) === confirmMessage ) {
if ( confirmTextWrapperClassesToRemove ) {
$passwordMatchStatus . removeClass ( confirmTextWrapperClassesToRemove ) ;
}
$passwordMatchStatus . html ( confirmMessage ) . addClass ( confirmClass ) ;
}
2014-01-27 21:41:32 +00:00
} ;
2017-05-19 22:12:53 +00:00
var passwordCheck = function passwordCheck ( ) {
2014-01-27 21:41:32 +00:00
if ( settings . password . showStrengthIndicator ) {
2020-09-29 23:44:28 +00:00
var result = Drupal . evaluatePasswordStrength ( $mainInput . val ( ) , settings . password ) ;
var $currentPasswordSuggestions = $ ( Drupal . theme ( 'passwordSuggestions' , settings . password , result . messageTips ) ) ;
if ( password . $suggestions . html ( ) !== $currentPasswordSuggestions . html ( ) ) {
password . $suggestions . replaceWith ( $currentPasswordSuggestions ) ;
password . $suggestions = $currentPasswordSuggestions . toggle ( result . strength !== 100 ) ;
}
2014-01-27 21:41:32 +00:00
2020-09-29 23:44:28 +00:00
if ( passwordStrengthBarClassesToRemove ) {
password . $strengthBar . removeClass ( passwordStrengthBarClassesToRemove ) ;
2014-01-27 21:41:32 +00:00
}
2020-09-29 23:44:28 +00:00
password . $strengthBar . css ( 'width' , "" . concat ( result . strength , "%" ) ) . addClass ( result . indicatorClass ) ;
password . $strengthTextWrapper . html ( result . indicatorText ) ;
2014-01-27 21:41:32 +00:00
}
2008-10-29 10:01:28 +00:00
2015-05-19 13:12:05 +00:00
if ( $confirmInput . val ( ) ) {
passwordCheckMatch ( $confirmInput . val ( ) ) ;
2020-09-29 23:44:28 +00:00
$passwordConfirmMessage . css ( {
2020-01-30 09:08:38 +00:00
visibility : 'visible'
} ) ;
2017-05-19 22:12:53 +00:00
} else {
2020-09-29 23:44:28 +00:00
$passwordConfirmMessage . css ( {
2020-01-30 09:08:38 +00:00
visibility : 'hidden'
} ) ;
2014-01-27 21:41:32 +00:00
}
2020-09-29 23:44:28 +00:00
if ( widgetClassesToRemove ) {
$passwordWidget . removeClass ( widgetClassesToRemove ) ;
addWidgetClasses ( ) ;
}
2014-01-27 21:41:32 +00:00
} ;
2008-10-19 20:55:07 +00:00
2020-09-29 23:44:28 +00:00
if ( widgetClassesToRemove ) {
addWidgetClasses ( ) ;
}
$mainInput . on ( 'input' , passwordCheck ) ;
2015-05-19 13:12:05 +00:00
$confirmInput . on ( 'input' , passwordCheck ) ;
2020-09-29 23:44:28 +00:00
} ) ;
2014-01-27 21:41:32 +00:00
}
} ;
2020-09-29 23:44:28 +00:00
Drupal . evaluatePasswordStrength = function ( password , passwordSettings ) {
2015-06-11 12:26:54 +00:00
password = password . trim ( ) ;
2020-01-30 09:08:38 +00:00
var indicatorText ;
var indicatorClass ;
2015-04-19 15:30:43 +00:00
var weaknesses = 0 ;
var strength = 100 ;
var msg = [ ] ;
2015-05-19 13:12:05 +00:00
var hasLowercase = /[a-z]/ . test ( password ) ;
var hasUppercase = /[A-Z]/ . test ( password ) ;
var hasNumbers = /[0-9]/ . test ( password ) ;
var hasPunctuation = /[^a-zA-Z0-9]/ . test ( password ) ;
var $usernameBox = $ ( 'input.username' ) ;
2020-09-29 23:44:28 +00:00
var username = $usernameBox . length > 0 ? $usernameBox . val ( ) : passwordSettings . username ;
2014-01-27 21:41:32 +00:00
2015-09-15 10:02:45 +00:00
if ( password . length < 12 ) {
2020-09-29 23:44:28 +00:00
msg . push ( passwordSettings . tooShort ) ;
2017-05-19 22:12:53 +00:00
strength -= ( 12 - password . length ) * 5 + 30 ;
2014-01-27 21:41:32 +00:00
}
2007-06-08 06:04:15 +00:00
2014-01-27 21:41:32 +00:00
if ( ! hasLowercase ) {
2020-09-29 23:44:28 +00:00
msg . push ( passwordSettings . addLowerCase ) ;
weaknesses += 1 ;
2014-01-27 21:41:32 +00:00
}
2020-01-30 09:08:38 +00:00
2014-01-27 21:41:32 +00:00
if ( ! hasUppercase ) {
2020-09-29 23:44:28 +00:00
msg . push ( passwordSettings . addUpperCase ) ;
weaknesses += 1 ;
2014-01-27 21:41:32 +00:00
}
2020-01-30 09:08:38 +00:00
2014-01-27 21:41:32 +00:00
if ( ! hasNumbers ) {
2020-09-29 23:44:28 +00:00
msg . push ( passwordSettings . addNumbers ) ;
weaknesses += 1 ;
2014-01-27 21:41:32 +00:00
}
2020-01-30 09:08:38 +00:00
2014-01-27 21:41:32 +00:00
if ( ! hasPunctuation ) {
2020-09-29 23:44:28 +00:00
msg . push ( passwordSettings . addPunctuation ) ;
weaknesses += 1 ;
2014-01-27 21:41:32 +00:00
}
2007-06-08 06:04:15 +00:00
2014-01-27 21:41:32 +00:00
switch ( weaknesses ) {
case 1 :
strength -= 12.5 ;
break ;
2009-09-21 08:52:41 +00:00
2014-01-27 21:41:32 +00:00
case 2 :
strength -= 25 ;
break ;
2007-06-08 06:04:15 +00:00
2014-01-27 21:41:32 +00:00
case 3 :
strength -= 40 ;
break ;
2007-06-08 06:04:15 +00:00
2014-01-27 21:41:32 +00:00
case 4 :
strength -= 40 ;
break ;
}
if ( password !== '' && password . toLowerCase ( ) === username . toLowerCase ( ) ) {
2020-09-29 23:44:28 +00:00
msg . push ( passwordSettings . sameAsUsername ) ;
2014-01-27 21:41:32 +00:00
strength = 5 ;
}
2020-09-29 23:44:28 +00:00
var cssClasses = Drupal . user . password . css ;
2014-01-27 21:41:32 +00:00
if ( strength < 60 ) {
2020-09-29 23:44:28 +00:00
indicatorText = passwordSettings . weak ;
indicatorClass = cssClasses . passwordWeak ;
2017-05-19 22:12:53 +00:00
} else if ( strength < 70 ) {
2020-09-29 23:44:28 +00:00
indicatorText = passwordSettings . fair ;
indicatorClass = cssClasses . passwordFair ;
2017-05-19 22:12:53 +00:00
} else if ( strength < 80 ) {
2020-09-29 23:44:28 +00:00
indicatorText = passwordSettings . good ;
indicatorClass = cssClasses . passwordGood ;
2017-05-19 22:12:53 +00:00
} else if ( strength <= 100 ) {
2020-09-29 23:44:28 +00:00
indicatorText = passwordSettings . strong ;
indicatorClass = cssClasses . passwordStrong ;
2014-01-27 21:41:32 +00:00
}
2020-09-29 23:44:28 +00:00
var messageTips = msg ;
msg = "" . concat ( passwordSettings . hasWeaknesses , "<ul><li>" ) . concat ( msg . join ( '</li><li>' ) , "</li></ul>" ) ;
return Drupal . deprecatedProperty ( {
target : {
strength : strength ,
message : msg ,
indicatorText : indicatorText ,
indicatorClass : indicatorClass ,
messageTips : messageTips
} ,
deprecatedProperty : 'message' ,
message : 'The message property is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. The markup should be constructed using messageTips property and Drupal.theme.passwordSuggestions. See https://www.drupal.org/node/3130352'
} ) ;
2014-01-27 21:41:32 +00:00
} ;
2020-09-29 23:44:28 +00:00
} ) ( jQuery , Drupal ) ;