Make WordPress Core

Ticket #34905: 34905.4.diff

File 34905.4.diff, 5.1 KB (added by peterwilsoncc, 9 years ago)
  • src/wp-admin/js/password-strength-meter.js

    diff --git src/wp-admin/js/password-strength-meter.js src/wp-admin/js/password-strength-meter.js
    index 2ac7e86..f42699a 100644
    var passwordStrength; 
    1818                        if (password1 != password2 && password2 && password2.length > 0)
    1919                                return 5;
    2020
     21                        if ( 'undefined' === typeof window.zxcvbn ) {
     22                                // Password strength unknown
     23                                return -1;
     24                        }
     25
    2126                        var result = zxcvbn( password1, blacklist );
    2227                        return result.score;
    2328                },
  • src/wp-admin/js/user-profile.js

    diff --git src/wp-admin/js/user-profile.js src/wp-admin/js/user-profile.js
    index 5ec77bc..3a37f2d 100644
     
    3030        function generatePassword() {
    3131                if ( typeof zxcvbn !== 'function' ) {
    3232                        setTimeout( generatePassword, 50 );
    33                 } else {
     33                        return;
     34                } else if ( ! $pass1.val() ) {
     35                        // zxcvbn loaded before user entered password.
    3436                        $pass1.val( $pass1.data( 'pw' ) );
    3537                        $pass1.trigger( 'pwupdate' ).trigger( 'wp-check-valid-field' );
    36                         if ( 1 !== parseInt( $toggleButton.data( 'start-masked' ), 10 ) ) {
    37                                 $pass1Wrap.addClass( 'show-password' );
    38                         } else {
    39                                 $toggleButton.trigger( 'click' );
    40                         }
    4138                }
     39                else {
     40                        // zxcvbn loaded after the user entered password, check strength.
     41                        check_pass_strength();
     42                        showOrHideWeakPasswordCheckbox();
     43                }
     44
     45                if ( 1 !== parseInt( $toggleButton.data( 'start-masked' ), 10 ) ) {
     46                        $pass1Wrap.addClass( 'show-password' );
     47                } else {
     48                        $toggleButton.trigger( 'click' );
     49                }
     50
     51                // Once zxcvbn loads, passwords strength is known.
     52                $( '#pw-weak-text-label' ).html( userProfileL10n.warnWeak );
    4253        }
    4354
    4455        function bindPass1() {
    45                 var passStrength = $('#pass-strength-result')[0];
    46 
    4756                currentPass = $pass1.val();
    4857
    4958                $pass1Wrap = $pass1.parent();
     
    8291                                $pass1Text.val( currentPass );
    8392                        }
    8493                        $pass1.add( $pass1Text ).removeClass( 'short bad good strong' );
    85 
    86                         if ( passStrength.className ) {
    87                                 $pass1.add( $pass1Text ).addClass( passStrength.className );
    88                                 if ( 'short' === passStrength.className || 'bad' === passStrength.className ) {
    89                                         if ( ! $weakCheckbox.prop( 'checked' ) ) {
    90                                                 $submitButtons.prop( 'disabled', true );
    91                                         }
    92                                         $weakRow.show();
    93                                 } else {
    94                                         $submitButtons.prop( 'disabled', false );
    95                                         $weakRow.hide();
    96                                 }
    97                         }
     94                        showOrHideWeakPasswordCheckbox();
    9895                } );
    9996        }
    10097
     
    289286                strength = wp.passwordStrength.meter( pass1, wp.passwordStrength.userInputBlacklist(), pass1 );
    290287
    291288                switch ( strength ) {
     289                        case -1:
     290                                $( '#pass-strength-result' ).addClass( 'bad' ).html( pwsL10n.unknown );
     291                                break;
    292292                        case 2:
    293293                                $('#pass-strength-result').addClass('bad').html( pwsL10n.bad );
    294294                                break;
     
    306306                }
    307307        }
    308308
     309        function showOrHideWeakPasswordCheckbox() {
     310                var passStrength = $('#pass-strength-result')[0];
     311
     312                if ( passStrength.className ) {
     313                        $pass1.add( $pass1Text ).addClass( passStrength.className );
     314                        if ( 'short' === passStrength.className || 'bad' === passStrength.className ) {
     315                                if ( ! $weakCheckbox.prop( 'checked' ) ) {
     316                                        $submitButtons.prop( 'disabled', true );
     317                                }
     318                                $weakRow.show();
     319                        } else {
     320                                $submitButtons.prop( 'disabled', false );
     321                                $weakRow.hide();
     322                        }
     323                }
     324        }
     325
    309326        $(document).ready( function() {
    310327                var $colorpicker, $stylesheet, user_id, current_user_id,
    311328                        select = $( '#display_name' );
  • src/wp-admin/user-edit.php

    diff --git src/wp-admin/user-edit.php src/wp-admin/user-edit.php
    index 46ac066..83b886f 100644
    if ( $show_password_fields = apply_filters( 'show_password_fields', true, $profi 
    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

    diff --git src/wp-includes/script-loader.php src/wp-includes/script-loader.php
    index e111842..2a6b433 100644
    function wp_default_scripts( &$scripts ) { 
    379379
    380380        $scripts->add( 'password-strength-meter', "/wp-admin/js/password-strength-meter$suffix.js", array( 'jquery', 'zxcvbn-async' ), false, 1 );
    381381        did_action( 'init' ) && $scripts->localize( 'password-strength-meter', 'pwsL10n', array(
     382                'unknown'  => _x( 'Password strength unknown', 'password strength' ),
    382383                'short'    => _x( 'Very weak', 'password strength' ),
    383384                'bad'      => _x( 'Weak', 'password strength' ),
    384385                'good'     => _x( 'Medium', 'password strength' ),
    function wp_default_scripts( &$scripts ) { 
    389390        $scripts->add( 'user-profile', "/wp-admin/js/user-profile$suffix.js", array( 'jquery', 'password-strength-meter', 'wp-util' ), false, 1 );
    390391        did_action( 'init' ) && $scripts->localize( 'user-profile', 'userProfileL10n', array(
    391392                'warn'     => __( 'Your new password has not been saved.' ),
     393                'warnWeak' => __( 'Confirm use of weak password.' ),
    392394                'show'     => __( 'Show' ),
    393395                'hide'     => __( 'Hide' ),
    394396                'cancel'   => __( 'Cancel' ),