Title: wp_set_password
Published: April 25, 2014
Last modified: August 20, 2026

---

# wp_set_password( string $password, int $user_id )

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/wp_set_password/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/wp_set_password/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/functions/wp_set_password/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/wp_set_password/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/wp_set_password/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_set_password/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_set_password/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/wp_set_password/?output_format=md#wp--skip-link--target)

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

## 󠀁[Description](https://developer.wordpress.org/reference/functions/wp_set_password/?output_format=md#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](https://developer.wordpress.org/reference/functions/wp_set_password/?output_format=md#parameters)󠁿

 `$password`stringrequired

The plaintext new user password.

`$user_id`intrequired

User ID.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/wp_set_password/?output_format=md#source)󠁿

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

    	$old_user_data = get_userdata( $user_id );

    	$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 );

    	/**
    	 * 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 );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/pluggable.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/pluggable.php#L3103)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/pluggable.php#L3103-L3135)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/wp_set_password/?output_format=md#hooks)󠁿

 [do_action( ‘wp_set_password’, string $password, int $user_id, WP_User $old_user_data )](https://developer.wordpress.org/reference/hooks/wp_set_password/)

Fires after the user password is set.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/wp_set_password/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_hash_password()](https://developer.wordpress.org/reference/functions/wp_hash_password/)`wp-includes/pluggable.php` |

Creates a hash of a plain text password.

  | 
| [clean_user_cache()](https://developer.wordpress.org/reference/functions/clean_user_cache/)`wp-includes/user.php` |

Cleans all user caches.

  | 
| [wpdb::update()](https://developer.wordpress.org/reference/classes/wpdb/update/)`wp-includes/class-wpdb.php` |

Updates a row in the table.

  | 
| [get_userdata()](https://developer.wordpress.org/reference/functions/get_userdata/)`wp-includes/pluggable.php` |

Retrieves user info by user ID.

  | 
| [do_action()](https://developer.wordpress.org/reference/functions/do_action/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to an action hook.

  |

[Show 2 more](https://developer.wordpress.org/reference/functions/wp_set_password/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/wp_set_password/?output_format=md#)

| Used by | Description | 
| [wp_authenticate_email_password()](https://developer.wordpress.org/reference/functions/wp_authenticate_email_password/)`wp-includes/user.php` |

Authenticates a user using the email and password.

  | 
| [reset_password()](https://developer.wordpress.org/reference/functions/reset_password/)`wp-includes/user.php` |

Handles resetting the user’s password.

  | 
| [wp_authenticate_username_password()](https://developer.wordpress.org/reference/functions/wp_authenticate_username_password/)`wp-includes/user.php` |

Authenticates a user, confirming the username and password are valid.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/wp_set_password/?output_format=md#changelog)󠁿

| Version | Description | 
| [6.8.0](https://developer.wordpress.org/reference/since/6.8.0/) | The password is now hashed using bcrypt by default instead of phpass. | 
| [2.5.0](https://developer.wordpress.org/reference/since/2.5.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/wp_set_password/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/functions/wp_set_password/?output_format=md#comment-content-640)
 2.   [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/wp_set_password/#comment-640)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_set_password%2F%23comment-640)
    Vote results for this note: 3[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_set_password%2F%23comment-640)
 4. Below is an example showing how to update a user’s password
 5.     ```php
        <?php
        $user_id = 1;
        $password = 'HelloWorld';
        wp_set_password( $password, $user_id );
        ?>
        ```
    
 6. **Please note:** This code should be deleted after ONE page load, otherwise the
    password will be reset on every subsequent load, sending the user back to the login
    screen each time.
 7.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_set_password%2F%3Freplytocom%3D640%23feedback-editor-640)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fwp_set_password%2F)
before being able to contribute a note or feedback.