wp_set_password

Updates the user's password with a new encrypted one.

Description

wp_set_password( (string) $password, (int) $user_id ); 

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 (2)

0. $password (string)
The plaintext new user password
1. $user_id (int)
The user id.

Usage

  1. if ( !function_exists( 'wp_set_password' ) ) { 
  2. require_once ABSPATH . WPINC . '/pluggable.php'; 
  3.  
  4. // The plaintext new user password 
  5. $password = ''; 
  6.  
  7. // The user id. 
  8. $user_id = -1; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wp_set_password($password, $user_id); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/pluggable.php  
  1. function wp_set_password( $password, $user_id ) { 
  2. global $wpdb; 
  3.  
  4. $hash = wp_hash_password( $password ); 
  5. $wpdb->update($wpdb->users, array('user_pass' => $hash, 'user_activation_key' => ''), array('ID' => $user_id) ); 
  6.  
  7. wp_cache_delete($user_id, 'users');