WordPress.org

Make WordPress Core

Changeset 6396


Ignore:
Timestamp:
12/17/2007 06:02:45 AM (10 years ago)
Author:
ryan
Message:

wp_set_password(). see #2394

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/pluggable.php

    r6387 r6396  
    305305    }
    306306
    307     $login = get_userdatabylogin($username);
    308 
    309     if ( !$login || ($login->user_login != $username) ) {
     307    $user = get_userdatabylogin($username);
     308
     309    if ( !$user || ($user->user_login != $username) ) {
    310310        $error = __('<strong>ERROR</strong>: Invalid username.');
    311311        return false;
    312312    }
    313313
    314     if ( !wp_check_password($password, $login->user_pass) ) {
     314    if ( !wp_check_password($password, $user->user_pass) ) {
    315315        $error = __('<strong>ERROR</strong>: Incorrect password.');
    316316        return false;
     
    318318
    319319    // If using old md5 password, rehash.
    320     if ( strlen($login->user_pass) <= 32 ) {
    321         $hash = wp_hash_password($password);
    322         $wpdb->query("UPDATE $wpdb->users SET user_pass = '$hash', user_activation_key = '' WHERE ID = '$login->ID'");
    323         wp_cache_delete($login->ID, 'users');
    324     }
     320    if ( strlen($user->user_pass) <= 32 )
     321        wp_set_password($password, $user->ID);
    325322
    326323    return true;
     
    771768endif;
    772769
     770if ( !function_exists('wp_set_password') ) :
     771function wp_set_password( $password, $user_id ) {
     772    global $wpdb;
     773
     774    $hash = wp_hash_password($password);
     775    $query = $wpdb->prepare("UPDATE $wpdb->users SET user_pass = %s, user_activation_key = '' WHERE ID = %d", $hash, $user_id);
     776    $wpdb->query($query);
     777    wp_cache_delete($user_id, 'users');
     778}
     779endif;
     780
    773781// Deprecated. Use wp_set_auth_cookie()
    774782if ( !function_exists('wp_setcookie') ) :
  • trunk/wp-login.php

    r6389 r6396  
    185185    // Generate something random for a password...
    186186    $new_pass = wp_generate_password();
    187     $new_hash = wp_hash_password($new_pass);
    188     $wpdb->query("UPDATE $wpdb->users SET user_pass = '$new_hash', user_activation_key = '' WHERE ID = '$user->ID'");
    189     wp_cache_delete($user->ID, 'users');
     187    wp_set_password($new_pass, $user->ID);
    190188    $message  = sprintf(__('Username: %s'), $user->user_login) . "\r\n";
    191189    $message .= sprintf(__('Password: %s'), $new_pass) . "\r\n";
Note: See TracChangeset for help on using the changeset viewer.