diff --git src/js/_enqueues/admin/user-profile.js src/js/_enqueues/admin/user-profile.js
index ff4830242c..4fc0a2134f 100644
|
|
|
14 | 14 | $toggleButton, |
15 | 15 | $submitButtons, |
16 | 16 | $submitButton, |
17 | | currentPass; |
| 17 | currentPass, |
| 18 | $passwordWrapper; |
18 | 19 | |
19 | 20 | function generatePassword() { |
20 | 21 | if ( typeof zxcvbn !== 'function' ) { |
21 | 22 | setTimeout( generatePassword, 50 ); |
22 | 23 | return; |
23 | | } else if ( ! $pass1.val() ) { |
24 | | // zxcvbn loaded before user entered password. |
| 24 | } else if ( ! $pass1.val() || $passwordWrapper.hasClass( 'is-open' ) ) { |
| 25 | // zxcvbn loaded before user entered password, or generating new password. |
25 | 26 | $pass1.val( $pass1.data( 'pw' ) ); |
26 | 27 | $pass1.trigger( 'pwupdate' ); |
27 | 28 | showOrHideWeakPasswordCheckbox(); |
28 | | } |
29 | | else { |
| 29 | } else { |
30 | 30 | // zxcvbn loaded after the user entered password, check strength. |
31 | 31 | check_pass_strength(); |
32 | 32 | showOrHideWeakPasswordCheckbox(); |
33 | 33 | } |
34 | 34 | |
| 35 | // Install screen. |
35 | 36 | if ( 1 !== parseInt( $toggleButton.data( 'start-masked' ), 10 ) ) { |
| 37 | // Show the password not masked if admin_password hasn't been posted yet. |
36 | 38 | $pass1.attr( 'type', 'text' ); |
37 | 39 | } else { |
| 40 | // Otherwise, mask the password. |
38 | 41 | $toggleButton.trigger( 'click' ); |
39 | 42 | } |
40 | 43 | |
… |
… |
|
56 | 59 | |
57 | 60 | currentPass = $pass1.val(); |
58 | 61 | |
| 62 | // Refresh password strength area |
59 | 63 | $pass1.removeClass( 'short bad good strong' ); |
60 | 64 | showOrHideWeakPasswordCheckbox(); |
61 | 65 | } ); |
… |
… |
|
84 | 88 | $pass1.attr( 'type', 'password' ); |
85 | 89 | resetToggle( true ); |
86 | 90 | } |
87 | | |
88 | | $pass1.focus(); |
89 | | |
90 | | if ( ! _.isUndefined( $pass1[0].setSelectionRange ) ) { |
91 | | $pass1[0].setSelectionRange( 0, 100 ); |
92 | | } |
93 | 91 | }); |
94 | 92 | } |
95 | 93 | |
96 | 94 | function bindPasswordForm() { |
97 | | var $passwordWrapper, |
98 | | $generateButton, |
| 95 | var $generateButton, |
99 | 96 | $cancelButton; |
100 | 97 | |
101 | 98 | $pass1Row = $( '.user-pass1-wrap, .user-pass-wrap' ); |
… |
… |
|
123 | 120 | $pass1 = $( '#user_pass' ); |
124 | 121 | } |
125 | 122 | |
126 | | /** |
| 123 | /* |
127 | 124 | * Fix a LastPass mismatch issue, LastPass only changes pass2. |
128 | 125 | * |
129 | 126 | * This fixes the issue by copying any changes from the hidden |
… |
… |
|
149 | 146 | |
150 | 147 | bindToggleButton(); |
151 | 148 | |
152 | | if ( $generateButton.length ) { |
153 | | $passwordWrapper.hide(); |
154 | | } |
155 | | |
156 | 149 | $generateButton.show(); |
157 | 150 | $generateButton.on( 'click', function () { |
158 | 151 | updateLock = true; |
159 | 152 | |
160 | | $generateButton.hide(); |
161 | | $passwordWrapper.show(); |
| 153 | // Make sure the password fields are shown. |
| 154 | $generateButton.attr( 'aria-expanded', 'true' ); |
| 155 | $passwordWrapper |
| 156 | .show() |
| 157 | .addClass( 'is-open' ); |
162 | 158 | |
163 | 159 | // Enable the inputs when showing. |
164 | 160 | $pass1.attr( 'disabled', false ); |
165 | 161 | $pass2.attr( 'disabled', false ); |
166 | 162 | |
167 | | if ( $pass1.val().length === 0 ) { |
168 | | generatePassword(); |
169 | | } |
170 | | } ); |
171 | | |
172 | | $cancelButton = $pass1Row.find( 'button.wp-cancel-pw' ); |
173 | | $cancelButton.on( 'click', function () { |
174 | | updateLock = false; |
175 | | |
176 | | // Clear any entered password. |
177 | | $pass1.val( '' ); |
178 | | |
179 | | // Generate a new password. |
| 163 | // Generate a new password each time it opens |
180 | 164 | wp.ajax.post( 'generate-password' ) |
181 | 165 | .done( function( data ) { |
| 166 | // Set password in data attribute |
182 | 167 | $pass1.data( 'pw', data ); |
183 | | } ); |
184 | 168 | |
185 | | $generateButton.show().focus(); |
186 | | $passwordWrapper.hide(); |
| 169 | // Actually update the password |
| 170 | generatePassword(); |
187 | 171 | |
188 | | $weakRow.hide( 0, function () { |
189 | | $weakCheckbox.removeProp( 'checked' ); |
190 | | } ); |
| 172 | // Show generated password in plaintext by default |
| 173 | resetToggle ( false ); |
| 174 | } ); |
| 175 | } ); |
| 176 | |
| 177 | $cancelButton = $pass1Row.find( 'button.wp-cancel-pw' ); |
| 178 | $cancelButton.on( 'click', function () { |
| 179 | updateLock = false; |
191 | 180 | |
192 | 181 | // Disable the inputs when hiding to prevent autofill and submission. |
193 | 182 | $pass1.prop( 'disabled', true ); |
194 | 183 | $pass2.prop( 'disabled', true ); |
195 | 184 | |
| 185 | // Clear password field and update the ui |
| 186 | $pass1.val( '' ).trigger( 'pwupdate' ); |
196 | 187 | resetToggle( false ); |
197 | 188 | |
198 | 189 | if ( $pass1Row.closest( 'form' ).is( '#your-profile' ) ) { |
199 | | // Clear password field to prevent update. |
200 | | $pass1.val( '' ).trigger( 'pwupdate' ); |
| 190 | // Stop an empty password from being submitted as a change |
201 | 191 | $submitButtons.prop( 'disabled', false ); |
202 | 192 | } |
203 | 193 | } ); |
… |
… |
|
399 | 389 | |
400 | 390 | window.generatePassword = generatePassword; |
401 | 391 | |
402 | | /* Warn the user if password was generated but not saved */ |
| 392 | // Warn the user if password was generated but not saved. |
403 | 393 | $( window ).on( 'beforeunload', function () { |
404 | 394 | if ( true === updateLock ) { |
405 | 395 | return userProfileL10n.warn; |
diff --git src/wp-admin/css/forms.css src/wp-admin/css/forms.css
index f86fbddd68..512a847329 100644
|
|
fieldset label, |
529 | 529 | margin: 0 0 1em; |
530 | 530 | } |
531 | 531 | |
| 532 | .wp-generate-pw { |
| 533 | margin-top: 1em; |
| 534 | } |
| 535 | |
| 536 | .wp-pwd { |
| 537 | margin-top: 1em; |
| 538 | } |
| 539 | |
532 | 540 | #misc-publishing-actions label { |
533 | 541 | vertical-align: baseline; |
534 | 542 | } |
diff --git src/wp-admin/user-edit.php src/wp-admin/user-edit.php
index de5131af24..bb75b5dc59 100644
|
|
endif; |
628 | 628 | <th><label for="pass1"><?php _e( 'New Password' ); ?></label></th> |
629 | 629 | <td> |
630 | 630 | <input class="hidden" value=" " /><!-- #24364 workaround --> |
631 | | <button type="button" class="button wp-generate-pw hide-if-no-js"><?php _e( 'Generate Password' ); ?></button> |
| 631 | <button type="button" class="button wp-generate-pw hide-if-no-js" aria-expanded="false"><?php _e( 'Set New Password' ); ?></button> |
632 | 632 | <div class="wp-pwd hide-if-js"> |
633 | 633 | <span class="password-input-wrapper"> |
634 | 634 | <input type="password" name="pass1" id="pass1" class="regular-text" value="" autocomplete="off" data-pw="<?php echo esc_attr( wp_generate_password( 24 ) ); ?>" aria-describedby="pass-strength-result" /> |
… |
… |
endif; |
637 | 637 | <span class="dashicons dashicons-hidden" aria-hidden="true"></span> |
638 | 638 | <span class="text"><?php _e( 'Hide' ); ?></span> |
639 | 639 | </button> |
640 | | <button type="button" class="button wp-cancel-pw hide-if-no-js" data-toggle="0" aria-label="<?php esc_attr_e( 'Cancel password change' ); ?>"> |
| 640 | <button type="button" class="button wp-cancel-pw hide-if-no-js" data-toggle="0" aria-label="<?php esc_attr_e( 'Cancel' ); ?>"> |
641 | 641 | <span class="dashicons dashicons-no" aria-hidden="true"></span> |
642 | 642 | <span class="text"><?php _e( 'Cancel' ); ?></span> |
643 | 643 | </button> |
… |
… |
endif; |
648 | 648 | <tr class="user-pass2-wrap hide-if-js"> |
649 | 649 | <th scope="row"><label for="pass2"><?php _e( 'Repeat New Password' ); ?></label></th> |
650 | 650 | <td> |
651 | | <input name="pass2" type="password" id="pass2" class="regular-text" value="" autocomplete="off" /> |
652 | | <p class="description"><?php _e( 'Type your new password again.' ); ?></p> |
| 651 | <input name="pass2" type="password" id="pass2" class="regular-text" value="" autocomplete="off" aria-describedby="pass2-desc" /> |
| 652 | <?php if ( IS_PROFILE_PAGE ) : ?> |
| 653 | <p class="description" id="pass2-desc"><?php _e( 'Type your new password again.' ); ?></p> |
| 654 | <?php else : ?> |
| 655 | <p class="description" id="pass2-desc"><?php _e( 'Type the new password again.' ); ?></p> |
| 656 | <?php endif; ?> |
653 | 657 | </td> |
654 | 658 | </tr> |
655 | 659 | <tr class="pw-weak"> |
… |
… |
endif; |
657 | 661 | <td> |
658 | 662 | <label> |
659 | 663 | <input type="checkbox" name="pw_weak" class="pw-checkbox" /> |
660 | | <span id="pw-weak-text-label"><?php _e( 'Confirm use of potentially weak password' ); ?></span> |
| 664 | <span id="pw-weak-text-label"><?php _e( 'Confirm use of weak password' ); ?></span> |
661 | 665 | </label> |
662 | 666 | </td> |
663 | 667 | </tr> |
diff --git src/wp-admin/user-new.php src/wp-admin/user-new.php
index be4b5083bc..c2d9d0532a 100644
|
|
if ( current_user_can( 'create_users' ) ) { |
507 | 507 | </th> |
508 | 508 | <td> |
509 | 509 | <input class="hidden" value=" " /><!-- #24364 workaround --> |
510 | | <button type="button" class="button wp-generate-pw hide-if-no-js"><?php _e( 'Show password' ); ?></button> |
511 | | <div class="wp-pwd hide-if-js"> |
| 510 | <button type="button" class="button wp-generate-pw hide-if-no-js" aria-expanded="true"><?php _e( 'Generate New Password' ); ?></button> |
| 511 | <div class="wp-pwd"> |
512 | 512 | <?php $initial_password = wp_generate_password( 24 ); ?> |
513 | 513 | <span class="password-input-wrapper"> |
514 | 514 | <input type="password" name="pass1" id="pass1" class="regular-text" autocomplete="off" data-reveal="1" data-pw="<?php echo esc_attr( $initial_password ); ?>" aria-describedby="pass-strength-result" /> |
… |
… |
if ( current_user_can( 'create_users' ) ) { |
517 | 517 | <span class="dashicons dashicons-hidden" aria-hidden="true"></span> |
518 | 518 | <span class="text"><?php _e( 'Hide' ); ?></span> |
519 | 519 | </button> |
520 | | <button type="button" class="button wp-cancel-pw hide-if-no-js" data-toggle="0" aria-label="<?php esc_attr_e( 'Cancel password change' ); ?>"> |
| 520 | <button type="button" class="button wp-cancel-pw hide-if-no-js" data-toggle="0" aria-label="<?php esc_attr_e( 'Cancel' ); ?>"> |
521 | 521 | <span class="dashicons dashicons-no" aria-hidden="true"></span> |
522 | 522 | <span class="text"><?php _e( 'Cancel' ); ?></span> |
523 | 523 | </button> |
… |
… |
if ( current_user_can( 'create_users' ) ) { |
528 | 528 | <tr class="form-field form-required user-pass2-wrap hide-if-js"> |
529 | 529 | <th scope="row"><label for="pass2"><?php _e( 'Repeat Password' ); ?> <span class="description"><?php _e( '(required)' ); ?></span></label></th> |
530 | 530 | <td> |
531 | | <input name="pass2" type="password" id="pass2" autocomplete="off" /> |
| 531 | <input name="pass2" type="password" id="pass2" autocomplete="off" aria-describedby="pass2-desc" /> |
| 532 | <p class="description" id="pass2-desc"><?php _e( 'Type the password again.' ); ?></p> |
532 | 533 | </td> |
533 | 534 | </tr> |
534 | 535 | <tr class="pw-weak"> |