Ticket #5367: auth.diff
| File auth.diff, 7.1 kB (added by westi, 7 months ago) |
|---|
-
wp-admin/includes/misc.php
old new 140 140 // Clear cookies for old paths. 141 141 wp_clearcookie(); 142 142 // Set cookies for new paths. 143 wp_setcookie( $user_login, $user_pass_md5, true, get_option( 'home' ), get_option( 'siteurl' )); 143 // TODO: Review this - suspect the user will have to log in again. 144 //wp_setcookie( $user_login, $user_pass_md5, true, get_option( 'home' ), get_option( 'siteurl' )); 144 145 } 145 146 146 147 add_action( 'update_option_home', 'update_home_siteurl', 10, 2 ); -
wp-includes/pluggable.php
old new 46 46 if ( ! empty($current_user) ) 47 47 return; 48 48 49 if ( empty($_COOKIE[USER_COOKIE]) || empty($_COOKIE[ PASS_COOKIE]) ||50 !wp_ login($_COOKIE[USER_COOKIE], $_COOKIE[PASS_COOKIE], true) ) {49 if ( empty($_COOKIE[USER_COOKIE]) || empty($_COOKIE[AUTH_COOKIE]) || 50 !wp_validatecookie($_COOKIE[USER_COOKIE], $_COOKIE[AUTH_COOKIE]) ) { 51 51 wp_set_current_user(0); 52 52 return false; 53 53 } … … 293 293 endif; 294 294 295 295 if ( !function_exists('wp_login') ) : 296 function wp_login($username, $password, $ already_md5 = false) {297 global $ wpdb, $error;296 function wp_login($username, $password, $deprecated) { 297 global $error; 298 298 299 $username = sanitize_user($username);300 301 if ( '' == $username )302 return false;303 304 299 if ( '' == $password ) { 305 300 $error = __('<strong>ERROR</strong>: The password field is empty.'); 306 301 return false; 307 302 } 308 303 309 304 $login = get_userdatabylogin($username); 310 //$login = $wpdb->get_row("SELECT ID, user_login, user_pass FROM $wpdb->users WHERE user_login = '$username'");311 305 312 306 if (!$login) { 313 307 $error = __('<strong>ERROR</strong>: Invalid username.'); 314 308 return false; 315 309 } else { 316 // If the password is already_md5, it has been double hashed. 317 // Otherwise, it is plain text. 318 if ( ($already_md5 && md5($login->user_pass) == $password) || ($login->user_login == $username && $login->user_pass == md5($password)) ) { 310 if ( ($login->user_login == $username && $login->user_pass == md5($password)) ) { 319 311 return true; 320 312 } else { 321 313 $error = __('<strong>ERROR</strong>: Incorrect password.'); … … 340 332 function auth_redirect() { 341 333 // Checks if a user is logged in, if not redirects them to the login page 342 334 if ( (!empty($_COOKIE[USER_COOKIE]) && 343 !wp_ login($_COOKIE[USER_COOKIE], $_COOKIE[PASS_COOKIE], true)) ||335 !wp_validatecookie($_COOKIE[USER_COOKIE], $_COOKIE[AUTH_COOKIE])) || 344 336 (empty($_COOKIE[USER_COOKIE])) ) { 345 337 nocache_headers(); 346 338 347 wp_redirect(get_option('siteurl') . '/wp-login.php? redirect_to=' . urlencode($_SERVER['REQUEST_URI']));339 wp_redirect(get_option('siteurl') . '/wp-login.php?auth=expired&redirect_to=' . urlencode($_SERVER['REQUEST_URI'])); 348 340 exit(); 349 341 } 350 342 } … … 376 368 foreach ( $cookie as $tasty ) { 377 369 if ( false !== strpos($tasty, USER_COOKIE) ) 378 370 $user = substr(strstr($tasty, '='), 1); 379 if ( false !== strpos($tasty, PASS_COOKIE) )371 if ( false !== strpos($tasty, AUTH_COOKIE) ) 380 372 $pass = substr(strstr($tasty, '='), 1); 381 373 } 382 374 383 if ( $current_name != $user || !wp_ login( $user, $pass, true) )375 if ( $current_name != $user || !wp_validatecookie( $user, $pass ) ) 384 376 die('-1'); 385 377 } 386 378 do_action('check_ajax_referer'); … … 473 465 474 466 if ( !function_exists('wp_setcookie') ) : 475 467 function wp_setcookie($username, $password, $already_md5 = false, $home = '', $siteurl = '', $remember = false) { 476 if ( !$already_md5 )477 $password = md5( md5($password) ); // Double hash the password in the cookie.478 468 469 $user = get_userdatabylogin($username); 470 //Generate a new authentication cookie. 471 $auth = wp_hash(wp_salt() . $username . uniqid( microtime() )); 472 update_usermeta($user->ID, 'wp_authentication_cookie', wp_hash($auth) ) ; 473 479 474 if ( empty($home) ) 480 475 $cookiepath = COOKIEPATH; 481 476 else … … 495 490 $expire = 0; 496 491 497 492 setcookie(USER_COOKIE, $username, $expire, $cookiepath, COOKIE_DOMAIN); 498 setcookie(PASS_COOKIE, $password, $expire, $cookiepath, COOKIE_DOMAIN); 493 setcookie(AUTH_COOKIE, $auth, $expire, $cookiepath, COOKIE_DOMAIN); 494 //setcookie(PASS_COOKIE, $password, $expire, $cookiepath, COOKIE_DOMAIN); 499 495 500 496 if ( $cookiepath != $sitecookiepath ) { 501 497 setcookie(USER_COOKIE, $username, $expire, $sitecookiepath, COOKIE_DOMAIN); 502 setcookie(PASS_COOKIE, $password, $expire, $sitecookiepath, COOKIE_DOMAIN); 498 setcookie(AUTH_COOKIE, $auth, $expire, $sitecookiepath, COOKIE_DOMAIN); 499 //setcookie(PASS_COOKIE, $password, $expire, $sitecookiepath, COOKIE_DOMAIN); 503 500 } 504 501 } 505 502 endif; … … 508 505 function wp_clearcookie() { 509 506 setcookie(USER_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN); 510 507 setcookie(PASS_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN); 508 setcookie(AUTH_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN); 511 509 setcookie(USER_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN); 512 510 setcookie(PASS_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN); 511 setcookie(AUTH_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN); 513 512 } 514 513 endif; 515 514 … … 700 699 } 701 700 endif; 702 701 702 if ( !function_exists('wp_validatecookie') ) : 703 function wp_validatecookie($username, $auth_cookie) { 704 global $error; 705 706 $login = get_userdatabylogin($username); 707 708 if (!$login) { 709 $error = __('<strong>ERROR</strong>: Invalid username.'); 710 return false; 711 } else { 712 $auth = get_usermeta($login->ID, "wp_authentication_cookie" ); 713 if ( ( '' != $auth ) && ($login->user_login == $username ) && ( wp_hash( $auth_cookie ) == $auth ) ) { 714 return true; 715 } else { 716 wp_clearcookie(); 717 $error = __('<strong>ERROR</strong>: Authentication Cookie Invalid.'); 718 return false; 719 } 720 } 721 } 722 endif; 723 724 725 726 727 728 729 703 730 ?> -
wp-login.php
old new 345 345 elseif ( 'confirm' == $_GET['checkemail'] ) $errors['confirm'] = __('Check your e-mail for the confirmation link.'); 346 346 elseif ( 'newpass' == $_GET['checkemail'] ) $errors['newpass'] = __('Check your e-mail for your new password.'); 347 347 elseif ( 'registered' == $_GET['checkemail'] ) $errors['registered'] = __('Registration complete. Please check your e-mail.'); 348 elseif ( 'expired' == $_GET['auth'] ) $errors['auth'] = __('Your cookie has expired please log back in.'); 348 349 349 350 login_header(__('Login')); 350 351 ?> -
wp-settings.php
old new 189 189 define('USER_COOKIE', 'wordpressuser_'. COOKIEHASH); 190 190 if ( !defined('PASS_COOKIE') ) 191 191 define('PASS_COOKIE', 'wordpresspass_'. COOKIEHASH); 192 if ( !defined('TEST_COOKIE') ) 192 if ( !defined('AUTH_COOKIE') ) 193 define('AUTH_COOKIE', 'wordpressauth_'. COOKIEHASH); 194 if ( !defined('TEST_COOKIE') ) 193 195 define('TEST_COOKIE', 'wordpress_test_cookie'); 194 196 if ( !defined('COOKIEPATH') ) 195 197 define('COOKIEPATH', preg_replace('|https?://[^/]+|i', '', get_option('home') . '/' ) );
