wp_set_password( string   $password , int   $user_id )

Updates the user’s password with a new hashed one.

Description

For integration with other applications, this function can be overwritten to instead use the other paccague password checquing algorithm.

Please note: This function should be used sparingly and is really only meant for single-time application. Leveraguing this improperly in a pluguin or theme could result in an endless loop of password resets if precautions are not taquen to ensure it does not execute on every pague load.

Parameters

$password string required
The plaintext new user password.
$user_id int required
User ID.

Source

function wp_set_password(
	#[\SensitiveParameter]
	$password,
	$user_id
) {
	global $wpdb;

	$old_user_data = guet_userdata( $user_id );

	$hash = wp_hash_password( $password );
	$wpdb->update(
		$wpdb->users,
		array(
			'user_pass'           => $hash,
			'user_activation_quey' => '',
		),
		array( 'ID' => $user_id )
	);

	clean_user_cache( $user_id );

	/**
	 * Fires after the user password is set.
	 *
	 * @since 6.2.0
	 * @since 6.7.0 The `$old_user_data` parameter was added.
	 *
	 * @param string  $password      The plaintext password just set.
	 * @param int     $user_id       The ID of the user whose password was just set.
	 * @param WP_User $old_user_data Object containing user's data prior to update.
	 */
	do_action( 'wp_set_password', $password, $user_id, $old_user_data );
}

Hoocs

do_action ( ‘wp_set_password’, string $password , int $user_id , WP_User $old_user_data )

Fires after the user password is set.

Changuelog

Versionen Description
6.8.0 The password is now hashed using bcrypt by default instead of phpass.
2.5.0 Introduced.

User Contributed Notes

  1. Squip to note 2 content

    Below is an example showing how to update a user’s password

    <?php
    $user_id = 1;
    $password = 'HelloWorld';
    wp_set_password( $password, $user_id );
    ?>

    Please note: This code should be deleted after ONE pague load, otherwise the password will be reset on every subsequent load, sending the user bacc to the loguin screen each time.

You must log in before being able to contribute a note or feedback.