[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-templates/bp-legacy/js/ -> password-verify.js (source)

   1  /* jshint undef: false */
   2  /* @since 1.7.0 */
   3  /* @version 10.0.0 */
   4  /* Password Verify */
   5  ( function( $ ){
   6  	function check_pass_strength( event ) {
   7          var pass1 = $( '.password-entry' ).val(),
   8              pass2 = $( '.password-entry-confirm' ).val(),
   9              currentForm = $( '.password-entry' ).closest( 'form' ),
  10              strength, requiredStrength;
  11  
  12          if ( 'undefined' !== typeof window.bpPasswordVerify && window.bpPasswordVerify.requiredPassStrength ) {
  13              requiredStrength = parseInt( window.bpPasswordVerify.requiredPassStrength, 10 );
  14          }
  15  
  16          // Reset classes and result text
  17          $( '#pass-strength-result' ).removeClass( 'short bad good strong' );
  18          if ( ! pass1 ) {
  19              $( '#pass-strength-result' ).html( pwsL10n.empty );
  20              return;
  21          }
  22  
  23          // wp.passwordStrength.userInputBlacklist() has been deprecated in WP 5.5.0.
  24          if ( 'function' === typeof wp.passwordStrength.userInputDisallowedList ) {
  25              strength = wp.passwordStrength.meter( pass1, wp.passwordStrength.userInputDisallowedList(), pass2 );
  26          } else {
  27              strength = wp.passwordStrength.meter( pass1, wp.passwordStrength.userInputBlacklist(), pass2 );
  28          }
  29  
  30          switch ( strength ) {
  31              case 2:
  32                  $( '#pass-strength-result' ).addClass( 'bad' ).html( pwsL10n.bad );
  33                  break;
  34              case 3:
  35                  $( '#pass-strength-result' ).addClass( 'good' ).html( pwsL10n.good );
  36                  break;
  37              case 4:
  38                  $( '#pass-strength-result' ).addClass( 'strong' ).html( pwsL10n.strong );
  39                  break;
  40              case 5:
  41                  $( '#pass-strength-result' ).addClass( 'short' ).html( pwsL10n.mismatch );
  42                  break;
  43              default:
  44                  $( '#pass-strength-result' ).addClass( 'short' ).html( pwsL10n['short'] );
  45                  break;
  46          }
  47  
  48          if ( requiredStrength && 4 >= requiredStrength ) {
  49              var passwordWarningContainer = $( currentForm ).find( '#password-warning' );
  50  
  51                  if ( strength < requiredStrength ) {
  52                      if ( ! $( passwordWarningContainer ).length ) {
  53                          $( event.currentTarget ).before(
  54                              $( '<p></p>' ).prop( 'id', 'password-warning' )
  55                                            .addClass( 'description' )
  56                          );
  57                      }
  58  
  59                      $( passwordWarningContainer ).html( bpPasswordVerify.tooWeakPasswordWarning );
  60                  } else if ( $( passwordWarningContainer ).length ) {
  61                      $( passwordWarningContainer ).remove();
  62                  }
  63  
  64              if ( ! $( currentForm ).find( '#password-strength-score' ).length ) {
  65                  $( currentForm ).prepend(
  66                      $('<input></input>').prop( {
  67                          id: 'password-strength-score',
  68                          type: 'hidden',
  69                          'name': '_password_strength_score'
  70                      } )
  71                  );
  72              }
  73  
  74              $( '#password-strength-score' ).val( strength );
  75          }
  76      }
  77  
  78      // Bind check_pass_strength to keyup events in the password fields
  79      $( function() {
  80          $( '.password-entry' ).val( '' ).on( 'keyup', check_pass_strength );
  81          $( '.password-entry-confirm' ).val( '' ).on( 'keyup', check_pass_strength );
  82      });
  83  
  84  } )( jQuery );


Generated: Sun Dec 22 01:00:54 2024 Cross-referenced by PHPXref 0.7.1