Index: src/wp-admin/admin-ajax.php =================================================================== --- src/wp-admin/admin-ajax.php (revision 31467) +++ src/wp-admin/admin-ajax.php (working copy) @@ -61,7 +61,8 @@ 'query-attachments', 'save-attachment', 'save-attachment-compat', 'send-link-to-editor', 'send-attachment-to-editor', 'save-attachment-order', 'heartbeat', 'get-revision-diffs', 'save-user-color-scheme', 'update-widget', 'query-themes', 'parse-embed', 'set-attachment-thumbnail', - 'parse-media-shortcode', 'destroy-sessions', 'install-plugin', 'update-plugin' + 'parse-media-shortcode', 'destroy-sessions', 'install-plugin', 'update-plugin', + 'generate_password', ); // Register core Ajax calls. Index: src/wp-admin/css/forms.css =================================================================== --- src/wp-admin/css/forms.css (revision 31467) +++ src/wp-admin/css/forms.css (working copy) @@ -1004,10 +1004,6 @@ padding: 0; line-height: 2; } - - .form-field #domain { - max-width: none; - } } @media only screen and (max-width: 768px) { Index: src/wp-admin/includes/ajax-actions.php =================================================================== --- src/wp-admin/includes/ajax-actions.php (revision 31467) +++ src/wp-admin/includes/ajax-actions.php (working copy) @@ -2951,3 +2951,12 @@ wp_send_json_success( $status ); } + +/** + * Generates a password via ajax + * + * @since 4.1.0 + */ +function wp_ajax_generate_password() { + wp_die( wp_generate_password( 30 ) ); +} Index: src/wp-admin/js/password-strength-meter.js =================================================================== --- src/wp-admin/js/password-strength-meter.js (revision 31467) +++ src/wp-admin/js/password-strength-meter.js (working copy) @@ -72,4 +72,100 @@ // Backwards compatibility. passwordStrength = wp.passwordStrength.meter; + + /** + * Password generation tool. + * + * @param {sting} pass1 Selector for the first password field. + * @param {sting} pass2 Selector for the second password field. + * @param {sting} submit Selector for the generate password button. + * + */ + wp.passwordGenerator = { + + pass1: '', + pass2: '', + submit: '', + results: $('#pass-strength-result'), + + init: function( pass1, pass2, submit ) { + + wp.passwordGenerator.pass1 = $( pass1 ); + wp.passwordGenerator.pass2 = $( pass2 ); + wp.passwordGenerator.submit = $( submit ); + + wp.passwordGenerator.pass2.val('').keyup( wp.passwordGenerator.check_strength() ); + + // Handle user entering password + wp.passwordGenerator.pass1.val('').on( 'keyup', function() { + wp.passwordGenerator.check_strength(); + // Ensure fireld type is password + if ( 'text' === wp.passwordGenerator.pass1.attr( 'type' ) ) { + wp.passwordGenerator.pass1.attr( 'type', 'password' ); + } + if ( 'text' === wp.passwordGenerator.pass2.attr( 'type' ) ) { + wp.passwordGenerator.pass2.attr( 'type', 'password' ); + } + }); + + // Handle the Generate Password button + $( submit ).on('click', function() { + + wp.passwordGenerator.generate(); + + }); + + }, + + generate: function() { + + // Send an ajax request to the server to get a new password + $.post( ajaxurl, { action: 'generate_password' }, function(response) { + wp.passwordGenerator.pass1.val( response ).trigger( 'keyup' ); + wp.passwordGenerator.pass2.val( response ); + wp.passwordGenerator.check_strength(); + wp.passwordGenerator.pass1.attr( 'type', 'text' ); + wp.passwordGenerator.pass2.attr( 'type', 'text' ); + wp.passwordGenerator.pass1.focus().select(); + }); + + }, + + check_strength: function() { + + var pass1 = wp.passwordGenerator.pass1.val(), pass2 = wp.passwordGenerator.pass2.val(), strength; + + wp.passwordGenerator.results.removeClass('short bad good strong'); + if ( ! pass1 ) { + wp.passwordGenerator.results.html( pwsL10n.empty ); + return; + } + + strength = wp.passwordStrength.meter( pass1, wp.passwordStrength.userInputBlacklist(), pass2 ); + + switch ( strength ) { + case 2: + wp.passwordGenerator.results.addClass('bad').html( pwsL10n.bad ); + break; + case 3: + wp.passwordGenerator.results.addClass('good').html( pwsL10n.good ); + break; + case 4: + wp.passwordGenerator.results.addClass('strong').html( pwsL10n.strong ); + break; + case 5: + wp.passwordGenerator.results.addClass('short').html( pwsL10n.mismatch ); + break; + default: + wp.passwordGenerator.results.addClass('short').html( pwsL10n['short'] ); + } + + wp.passwordGenerator.results.show(); + + } + + }; + + wp.passwordGenerator.init( '#pass1', '#pass2', '#generate-password' ); + })(jQuery); \ No newline at end of file Index: src/wp-admin/js/user-profile.js =================================================================== --- src/wp-admin/js/user-profile.js (revision 31467) +++ src/wp-admin/js/user-profile.js (working copy) @@ -1,42 +1,16 @@ /* global ajaxurl, pwsL10n */ (function($){ - function check_pass_strength() { - var pass1 = $('#pass1').val(), pass2 = $('#pass2').val(), strength; + $(document).ready( function() { + var $colorpicker, $stylesheet, user_id, current_user_id, + select = $( '#display_name' ); - $('#pass-strength-result').removeClass('short bad good strong'); - if ( ! pass1 ) { - $('#pass-strength-result').html( pwsL10n.empty ); - return; - } + /* Passwords */ - strength = wp.passwordStrength.meter( pass1, wp.passwordStrength.userInputBlacklist(), pass2 ); + wp.passwordGenerator.init( '#pass1', '#pass2', '#generate-password' ); - switch ( strength ) { - case 2: - $('#pass-strength-result').addClass('bad').html( pwsL10n.bad ); - break; - case 3: - $('#pass-strength-result').addClass('good').html( pwsL10n.good ); - break; - case 4: - $('#pass-strength-result').addClass('strong').html( pwsL10n.strong ); - break; - case 5: - $('#pass-strength-result').addClass('short').html( pwsL10n.mismatch ); - break; - default: - $('#pass-strength-result').addClass('short').html( pwsL10n['short'] ); - } - } + /* End Passwords */ - $(document).ready( function() { - var $colorpicker, $stylesheet, user_id, current_user_id, - select = $( '#display_name' ); - - $('#pass1').val('').keyup( check_pass_strength ); - $('#pass2').val('').keyup( check_pass_strength ); - $('#pass-strength-result').show(); $('.color-palette').click( function() { $(this).siblings('input[name="admin_color"]').prop('checked', true); }); Index: src/wp-admin/user-edit.php =================================================================== --- src/wp-admin/user-edit.php (revision 31467) +++ src/wp-admin/user-edit.php (working copy) @@ -468,18 +468,31 @@