On this page
wp_set_password( string $password, int $user_id )
Updates the user’s password with a new encrypted one.
Description
For integration with other applications, this function can be overwritten to instead use the other package password checking algorithm.
Please note: This function should be used sparingly and is really only meant for single-time application. Leveraging this improperly in a plugin or theme could result in an endless loop of password resets if precautions are not taken to ensure it does not execute on every page load.
Parameters
$passwordstring Required-
The plaintext new user password.
$user_idint Required-
User ID.
Source
File: wp-includes/pluggable.php. View all references
function wp_set_password( $password, $user_id ) {
global $wpdb;
$hash = wp_hash_password( $password );
$wpdb->update(
$wpdb->users,
array(
'user_pass' => $hash,
'user_activation_key' => '',
),
array( 'ID' => $user_id )
);
clean_user_cache( $user_id );
}
Related
Uses
| Uses | Description |
|---|---|
| wp_hash_password() wp-includes/pluggable.php | Creates a hash (encrypt) of a plain text password. |
| clean_user_cache() wp-includes/user.php | Cleans all user caches. |
| wpdb::update() wp-includes/class-wpdb.php | Updates a row in the table. |
Used By
| Used By | Description |
|---|---|
| wp_check_password() wp-includes/pluggable.php | Checks the plaintext password against the encrypted Password. |
| reset_password() wp-includes/user.php | Handles resetting the user’s password. |
Changelog
| Version | Description |
|---|---|
| 2.5.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_set_password