wp_set_password

The timeline below displays how wordpress function wp_set_password has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.2

/**
 * Updates the user's password with a new encrypted one.
 *
 * 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.
 *
 * @since 2.5.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $password The plaintext new user password.
 * @param int    $user_id  User ID.
 */
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);
    /**
     * Fires after the user password is set.
     *
     * @since 6.2.0
     *
     * @param string $password The plaintext password just set.
     * @param int    $user_id  The ID of the user whose password was just set.
     */
    do_action('wp_set_password', $password, $user_id);
}

WordPress Version: 6.1

/**
 * Updates the user's password with a new encrypted one.
 *
 * 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.
 *
 * @since 2.5.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $password The plaintext new user password.
 * @param int    $user_id  User ID.
 */
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);
}

WordPress Version: 5.3

/**
 * Updates the user's password with a new encrypted one.
 *
 * 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.
 *
 * @since 2.5.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $password The plaintext new user password
 * @param int    $user_id  User ID
 */
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);
}

WordPress Version: 4.3

/**
 * Updates the user's password with a new encrypted one.
 *
 * 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.
 *
 * @since 2.5.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $password The plaintext new user password
 * @param int    $user_id  User ID
 */
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));
    wp_cache_delete($user_id, 'users');
}

WordPress Version: 4.1

/**
 * Updates the user's password with a new encrypted one.
 *
 * 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.
 *
 * @since 2.5.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param string $password The plaintext new user password
 * @param int $user_id User ID
 */
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));
    wp_cache_delete($user_id, 'users');
}

WordPress Version: 4.0

/**
 * Updates the user's password with a new encrypted one.
 *
 * 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.
 *
 * @since 2.5.0
 *
 * @uses $wpdb WordPress database object for queries
 * @uses wp_hash_password() Used to encrypt the user's password before passing to the database
 *
 * @param string $password The plaintext new user password
 * @param int $user_id User ID
 */
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));
    wp_cache_delete($user_id, 'users');
}

WordPress Version: 3.9

/**
 * Updates the user's password with a new encrypted one.
 *
 * For integration with other applications, this function can be overwritten to
 * instead use the other package password checking algorithm.
 *
 * @since 2.5.0
 *
 * @uses $wpdb WordPress database object for queries
 * @uses wp_hash_password() Used to encrypt the user's password before passing to the database
 *
 * @param string $password The plaintext new user password
 * @param int $user_id User ID
 */
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));
    wp_cache_delete($user_id, 'users');
}

WordPress Version: 3.7

/**
 * Updates the user's password with a new encrypted one.
 *
 * For integration with other applications, this function can be overwritten to
 * instead use the other package password checking algorithm.
 *
 * @since 2.5
 * @uses $wpdb WordPress database object for queries
 * @uses wp_hash_password() Used to encrypt the user's password before passing to the database
 *
 * @param string $password The plaintext new user password
 * @param int $user_id User ID
 */
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));
    wp_cache_delete($user_id, 'users');
}