Make WordPress Core

Ticket #34905: 34905.5.diff

File 34905.5.diff, 5.0 KB (added by adamsilverstein, 9 years ago)
  • src/wp-admin/js/password-strength-meter.js

     
    1818                        if (password1 != password2 && password2 && password2.length > 0)
    1919                                return 5;
    2020
     21                        if ( 'undefined' === typeof window.zxcvbn ) {
     22
     23                                // Password strength unknown.
     24                                return -1;
     25                        }
     26
    2127                        var result = zxcvbn( password1, blacklist );
    2228                        return result.score;
    2329                },
  • src/wp-admin/js/user-profile.js

     
    3030        function generatePassword() {
    3131                if ( typeof zxcvbn !== 'function' ) {
    3232                        setTimeout( generatePassword, 50 );
    33                 } else {
     33                        return;
     34                } else if ( ! $pass1.val() ) {
    3435
     36                        // zxcvbn loaded before user entered password.
    3537                        $pass1.val( $pass1.data( 'pw' ) );
    3638                        $pass1.trigger( 'pwupdate' ).trigger( 'wp-check-valid-field' );
    37                         if ( 1 !== parseInt( $toggleButton.data( 'start-masked' ), 10 ) ) {
    38                                 $pass1Wrap.addClass( 'show-password' );
    39                         } else {
    40                                 $toggleButton.trigger( 'click' );
    41                         }
    4239                }
     40                else {
    4341
     42                        // zxcvbn loaded after the user entered password, check strength.
     43                        check_pass_strength();
     44                        showOrHideWeakPasswordCheckbox();
     45                }
     46
     47                if ( 1 !== parseInt( $toggleButton.data( 'start-masked' ), 10 ) ) {
     48                        $pass1Wrap.addClass( 'show-password' );
     49                } else {
     50                        $toggleButton.trigger( 'click' );
     51                }
     52
     53                // Once zxcvbn loads, passwords strength is known.
     54                $( '#pw-weak-text-label' ).html( userProfileL10n.warnWeak );
    4455        }
    4556
    4657        function bindPass1() {
    47                 var passStrength = $('#pass-strength-result')[0];
    48 
    4958                currentPass = $pass1.val();
  • src/wp-admin/user-edit.php

     		$pass1Wrap = $pass1.parent();
    @@ -82,19 +91,7 @@
     				$pass1Text.val( currentPass );
     			}
     			$pass1.add( $pass1Text ).removeClass( 'short bad good strong' );
    -
    -			if ( passStrength.className ) {
    -				$pass1.add( $pass1Text ).addClass( passStrength.className );
    -				if ( 'short' === passStrength.className || 'bad' === passStrength.className ) {
    -					if ( ! $weakCheckbox.prop( 'checked' ) ) {
    -						$submitButtons.prop( 'disabled', true );
    -					}
    -					$weakRow.show();
    -				} else {
    -					$submitButtons.prop( 'disabled', false );
    -					$weakRow.hide();
    -				}
    -			}
    +			showOrHideWeakPasswordCheckbox();
     		} );
     	}
    
    @@ -289,6 +286,9 @@
     		strength = wp.passwordStrength.meter( pass1, wp.passwordStrength.userInputBlacklist(), pass1 );
    
     		switch ( strength ) {
    +			case -1:
    +				$( '#pass-strength-result' ).addClass( 'bad' ).html( pwsL10n.unknown );
    +				break;
     			case 2:
     				$('#pass-strength-result').addClass('bad').html( pwsL10n.bad );
     				break;
    @@ -306,6 +306,23 @@
     		}
     	}
    
    +	function showOrHideWeakPasswordCheckbox() {
    +		var passStrength = $('#pass-strength-result')[0];
    +
    +		if ( passStrength.className ) {
    +			$pass1.add( $pass1Text ).addClass( passStrength.className );
    +			if ( 'short' === passStrength.className || 'bad' === passStrength.className ) {
    +				if ( ! $weakCheckbox.prop( 'checked' ) ) {
    +					$submitButtons.prop( 'disabled', true );
    +				}
    +				$weakRow.show();
    +			} else {
    +				$submitButtons.prop( 'disabled', false );
    +				$weakRow.hide();
    +			}
    +		}
    +	}
    +
     	$(document).ready( function() {
     		var $colorpicker, $stylesheet, user_id, current_user_id,
     			select = $( '#display_name' );
     
    531531        <td>
    532532                <label>
    533533                        <input type="checkbox" name="pw_weak" class="pw-checkbox" />
    534                         <?php _e( 'Confirm use of weak password' ); ?>
     534                        <span id="pw-weak-text-label"><?php _e( 'Confirm use of potentially weak password' ); ?></span>
    535535                </label>
    536536        </td>
    537537</tr>
  • src/wp-includes/script-loader.php

     
    380380
    381381        $scripts->add( 'password-strength-meter', "/wp-admin/js/password-strength-meter$suffix.js", array( 'jquery', 'zxcvbn-async' ), false, 1 );
    382382        did_action( 'init' ) && $scripts->localize( 'password-strength-meter', 'pwsL10n', array(
     383                'unknown'  => _x( 'Password strength unknown', 'password strength' ),
    383384                'short'    => _x( 'Very weak', 'password strength' ),
    384385                'bad'      => _x( 'Weak', 'password strength' ),
    385386                'good'     => _x( 'Medium', 'password strength' ),
     
    390391        $scripts->add( 'user-profile', "/wp-admin/js/user-profile$suffix.js", array( 'jquery', 'password-strength-meter', 'wp-util' ), false, 1 );
    391392        did_action( 'init' ) && $scripts->localize( 'user-profile', 'userProfileL10n', array(
    392393                'warn'     => __( 'Your new password has not been saved.' ),
     394                'warnWeak' => __( 'Confirm use of weak password.' ),
    393395                'show'     => __( 'Show' ),
    394396                'hide'     => __( 'Hide' ),
    395397                'cancel'   => __( 'Cancel' ),