Users: Use `get_password_reset_key()` in `wp_new_user_notification()`.

Props mrasharirfan, spacedmonkey.
Fixes #45745.
Built from https://develop.svn.wordpress.org/trunk@45712


git-svn-id: http://core.svn.wordpress.org/trunk@45523 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2019-08-01 15:30:58 +00:00
parent 6623a824d0
commit 4a6461dcc2
2 changed files with 4 additions and 17 deletions

View File

@ -1893,9 +1893,6 @@ if ( ! function_exists( 'wp_new_user_notification' ) ) :
* @since 4.3.1 The `$plaintext_pass` parameter was deprecated. `$notify` added as a third parameter. * @since 4.3.1 The `$plaintext_pass` parameter was deprecated. `$notify` added as a third parameter.
* @since 4.6.0 The `$notify` parameter accepts 'user' for sending notification only to the user created. * @since 4.6.0 The `$notify` parameter accepts 'user' for sending notification only to the user created.
* *
* @global wpdb $wpdb WordPress database object for queries.
* @global PasswordHash $wp_hasher Portable PHP password hashing framework instance.
*
* @param int $user_id User ID. * @param int $user_id User ID.
* @param null $deprecated Not used (argument deprecated). * @param null $deprecated Not used (argument deprecated).
* @param string $notify Optional. Type of notification that should happen. Accepts 'admin' or an empty * @param string $notify Optional. Type of notification that should happen. Accepts 'admin' or an empty
@ -1911,7 +1908,6 @@ if ( ! function_exists( 'wp_new_user_notification' ) ) :
return; return;
} }
global $wpdb, $wp_hasher;
$user = get_userdata( $user_id ); $user = get_userdata( $user_id );
// The blogname option is escaped with esc_html on the way into the database in sanitize_option // The blogname option is escaped with esc_html on the way into the database in sanitize_option
@ -1971,19 +1967,10 @@ if ( ! function_exists( 'wp_new_user_notification' ) ) :
return; return;
} }
// Generate something random for a password reset key. $key = get_password_reset_key( $user );
$key = wp_generate_password( 20, false ); if ( is_wp_error( $key ) ) {
return;
/** This action is documented in wp-login.php */
do_action( 'retrieve_password_key', $user->user_login, $key );
// Now insert the key, hashed, into the DB.
if ( empty( $wp_hasher ) ) {
require_once ABSPATH . WPINC . '/class-phpass.php';
$wp_hasher = new PasswordHash( 8, true );
} }
$hashed = time() . ':' . $wp_hasher->HashPassword( $key );
$wpdb->update( $wpdb->users, array( 'user_activation_key' => $hashed ), array( 'user_login' => $user->user_login ) );
$switched_locale = switch_to_locale( get_user_locale( $user ) ); $switched_locale = switch_to_locale( get_user_locale( $user ) );

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.3-alpha-45711'; $wp_version = '5.3-alpha-45712';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.