Ticket #2394: 2394-salt.patch
File 2394-salt.patch, 5.3 KB (added by , 18 years ago) |
---|
-
wp-login.php
183 183 184 184 // Generate something random for a password... md5'ing current time with a rand salt 185 185 $new_pass = substr( md5( uniqid( microtime() ) ), 0, 7); 186 // By default we now create a salted password. 187 $salt = password_salt(); 188 $new_pass = $salt.md5($salt.$new_pass); 186 189 $wpdb->query("UPDATE $wpdb->users SET user_pass = MD5('$new_pass'), user_activation_key = '' WHERE user_login = '$user->user_login'"); 187 190 wp_cache_delete($user->ID, 'users'); 188 191 wp_cache_delete($user->user_login, 'userlogins'); -
wp-includes/pluggable.php
322 322 $error = __('<strong>ERROR</strong>: Invalid username.'); 323 323 return false; 324 324 } else { 325 // If the password is already_md5, it has been double hashed. 326 // Otherwise, it is plain text. 325 if (strlen($login->user_pass) > 32 && !$already_md5){ 326 // If the password is longer than a plain MD5 hash 327 // then presume that it's a salted password hash. 328 $hash = substr($login->user_pass,strlen($login->user_pass)-32,32); 329 $salt = substr($login->user_pass,0,strlen($login->user_pass)-32); 330 if (md5($salt . $password) == $hash) { 331 return true; 332 } else { 333 $error = __('<strong>ERROR</strong>: Incorrect Password.'); 334 $pwd = ''; 335 return false; 336 } 337 } elseif (strlen($login->user_pass) > 32 && $already_md5) { 338 // If the password is already_md5, it has been double hashed. 339 // Otherwise, it is plain text. 340 $hash = substr($login->user_pass,strlen($login->user_pass)-32,32); 341 $salt = substr($login->user_pass,0,strlen($login->user_pass)-32); 342 $test = md5($hash); 343 return ($test == $password); 344 } 345 327 346 if ( ($already_md5 && md5($login->user_pass) == $password) || ($login->user_login == $username && $login->user_pass == md5($password)) ) { 328 347 return true; 329 348 } else { … … 426 445 427 446 if ( !function_exists('wp_setcookie') ) : 428 447 function wp_setcookie($username, $password, $already_md5 = false, $home = '', $siteurl = '', $remember = false) { 429 if ( !$already_md5 ) 430 $password = md5( md5($password) ); // Double hash the password in the cookie. 448 $user = get_userdatabylogin($username); 431 449 450 if ( !$already_md5) { 451 if (strlen($user->user_pass)>32) { // Assume that the password is salted 452 // extract the hash and hash again. 453 $hash = substr($user->user_pass,strlen($user->user_pass)-32,32); 454 $password = md5($hash); 455 } else { // Unsalted passwords 456 $password = md5( md5($password) ); // Double hash the password in the cookie. 457 } 458 } 459 432 460 if ( empty($home) ) 433 461 $cookiepath = COOKIEPATH; 434 462 else -
wp-includes/registration.php
37 37 } 38 38 39 39 /** 40 * Generates a short random string for salting user passwords. This can 41 * be replaced with any function that returns a string less than 32 42 * characters in length (limitation is database field size) 43 */ 44 function password_salt(){ 45 for($i=0;$i<4;$i++){ 46 $x = rand(0,61); 47 if (0 <= $x && $x < 10 ) $salt = $salt . chr(48+$x); 48 if (10 <= $x && $x < 36) $salt = $salt . chr(55+$x); 49 if (36 <= $x && $x < 62) $salt = $salt . chr(61+$x); 50 } 51 return $salt; 52 } 53 54 /** 40 55 * Insert an user into the database. 41 56 * @global object $wpdb WordPress database layer. 42 57 * @param array $userdata An array of user data. … … 54 69 } else { 55 70 $update = false; 56 71 // Password is not hashed when creating new user. 57 $user_pass = md5($user_pass); 72 // By default we now create a salted password. 73 $salt = password_salt(); 74 $user_pass = $salt.md5($salt.$user_pass); 58 75 } 59 76 60 77 $user_login = sanitize_user($user_login, true); … … 163 180 // If password is changing, hash it now. 164 181 if ( ! empty($userdata['user_pass']) ) { 165 182 $plaintext_pass = $userdata['user_pass']; 166 $userdata['user_pass'] = md5($userdata['user_pass']); 183 // By default we now create a salted password. 184 $salt = password_salt(); 185 $userdata['user_pass'] = $salt.md5("$salt".$userdata['user_pass']); 167 186 } 168 187 169 188 // Merge old and new fields with new fields overwriting old ones. … … 214 233 return wp_create_user($username, $password, $email); 215 234 } 216 235 217 ?> 218 No newline at end of file 236 ?> -
wp-includes/user.php
21 21 } else { 22 22 $userdata = $cache_userdata[$user_login]; 23 23 } 24 return (md5($user_pass) == $userdata->user_pass); 24 25 $login = get_userdatabylogin($username); 26 if (strlen($login->user_pass) > 32) { // If new style salted passwords are being used 27 $hash = substr($login->user_pass,strlen($login->user_pass)-32,32); 28 $salt = substr($login->user_pass,0,strlen($login->user_pass)-32); 29 return (md5($salt . $user_pass) == $hash); 30 } else { // Revert to unsalted passwords 31 return (md5($user_pass) == $userdata->user_pass); 32 } 25 33 } 26 34 27 35 //