Ticket #2394: 2394-phpass.patch
File 2394-phpass.patch, 4.9 KB (added by , 17 years ago) |
---|
-
wp-login.php
1 1 <?php 2 require( dirname(__FILE__) . '/wp-includes/class-phpass.php'); 2 3 require( dirname(__FILE__) . '/wp-config.php' ); 3 4 4 5 $action = $_REQUEST['action']; … … 184 185 185 186 // Generate something random for a password... md5'ing current time with a rand salt 186 187 $new_pass = substr( md5( uniqid( microtime() ) ), 0, 7); 187 $wpdb->query("UPDATE $wpdb->users SET user_pass = MD5('$new_pass'), user_activation_key = '' WHERE user_login = '$user->user_login'"); 188 // By default, use the portable hash from phpass 189 $hasher = new PasswordHash(8, TRUE); 190 $new_hash = $hasher->HashPassword($new_pass); 191 $wpdb->query("UPDATE $wpdb->users SET user_pass = '$new_hash', user_activation_key = '' WHERE user_login = '$user->user_login'"); 188 192 wp_cache_delete($user->ID, 'users'); 189 193 wp_cache_delete($user->user_login, 'userlogins'); 190 194 $message = sprintf(__('Username: %s'), $user->user_login) . "\r\n"; -
wp-includes/pluggable.php
1 1 <?php 2 2 3 include_once(ABSPATH . WPINC . '/class-phpass.php'); 4 3 5 /* These functions can be replaced via plugins. They are loaded after 4 6 plugins are loaded. */ 5 7 … … 298 300 } else { 299 301 // If the password is already_md5, it has been double hashed. 300 302 // Otherwise, it is plain text. 303 if(strlen($login->user_pass) > 32 && !$already_md5) { 304 //If the stored hash is longer than an MD5, presume the 305 //new style phpass portable hash. 306 $hasher = new PasswordHash(8, TRUE); 307 if ($hasher->CheckPassword($password, $login->user_pass)){ 308 //Successful match 309 return true; 310 } else { 311 //Fail! 312 $pwd = ''; 313 return false; 314 } 315 } elseif (strlen($login->user_pass) > 32 && $already_md5) { 316 //If password has already already_md5 it has been double hashed 317 $test = md5($login->user_pass); 318 return ($test == $password); 319 } 301 320 if ( ($already_md5 && md5($login->user_pass) == $password) || ($login->user_login == $username && $login->user_pass == md5($password)) ) { 302 321 return true; 303 322 } else { … … 456 475 457 476 if ( !function_exists('wp_setcookie') ) : 458 477 function wp_setcookie($username, $password, $already_md5 = false, $home = '', $siteurl = '', $remember = false) { 459 if ( !$already_md5 ) 460 $password = md5( md5($password) ); // Double hash the password in the cookie. 478 $user = get_userdatabylogin($username); 479 if ( !$already_md5) { 480 $password = md5($user->user_pass); // Double hash the password in the cookie. 481 } 461 482 462 483 if ( empty($home) ) 463 484 $cookiepath = COOKIEPATH; -
wp-includes/registration.php
1 1 <?php 2 2 3 include_once(ABSPATH . WPINC . '/class-phpass.php'); 4 3 5 /** 4 6 * Checks whether the given username exists. 5 7 * @param string $username Username. … … 52 54 $update = true; 53 55 } else { 54 56 $update = false; 55 // Password is not hashed when creating new user. 56 $user_pass = md5($user_pass); 57 //If this is a new user being created, we need to 58 //use the phpass portable hash 59 $hasher = new PasswordHash(8, TRUE); 60 $user_pass = $hasher->HashPassword($user_pass); 57 61 } 58 62 59 63 $user_login = sanitize_user($user_login, true); … … 154 158 // If password is changing, hash it now. 155 159 if ( ! empty($userdata['user_pass']) ) { 156 160 $plaintext_pass = $userdata['user_pass']; 157 $userdata['user_pass'] = md5($userdata['user_pass']); 161 //Use the new phpass portable hash 162 $hasher = new PasswordHash(8, TRUE); 163 $userdata['user_pass'] = $hasher->HashPassword($userdata['user_pass']); 158 164 } 159 165 160 166 // Merge old and new fields with new fields overwriting old ones. … … 205 211 return wp_create_user($username, $password, $email); 206 212 } 207 213 208 ?> 209 No newline at end of file 214 ?> -
wp-includes/user.php
1 1 <?php 2 2 3 include_once(ABSPATH . WPINC . '/class-phpass.php'); 4 3 5 function get_profile($field, $user = false) { 4 6 global $wpdb; 5 7 if ( !$user ) … … 16 18 // TODO: xmlrpc only. Maybe move to xmlrpc.php. 17 19 function user_pass_ok($user_login,$user_pass) { 18 20 $userdata = get_userdatabylogin($user_login); 19 20 return (md5($user_pass) == $userdata->user_pass); 21 if (strlen($userdata->user_pass) > 32) { 22 //The hash is longer than MD5, so presume the new phpass portable hash 23 //is being used. 24 $hasher = new PasswordHash(8, TRUE); 25 return($hasher->CheckPassword($user_pass, $userdata->user_pass)); 26 } else { 27 return (md5($user_pass) == $userdata->user_pass); 28 } 21 29 } 22 30 23 31 //