Separate cookie generation from cookie set. Introduce wp_generate_auth_cookie(). see #5367

git-svn-id: http://svn.automattic.com/wordpress/trunk@6529 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2007-12-31 17:50:32 +00:00
parent eabc128c41
commit bed1da2844
1 changed files with 14 additions and 4 deletions

View File

@ -357,6 +357,19 @@ function wp_validate_auth_cookie($cookie = '') {
} }
endif; endif;
if ( !function_exists('wp_generate_auth_cookie') ) :
function wp_generate_auth_cookie($user_id, $expiration) {
$user = get_userdata($user_id);
$key = wp_hash($user->user_login . $expiration);
$hash = hash_hmac('md5', $user->user_login . $expiration, $key);
$cookie = $user->user_login . '|' . $expiration . '|' . $hash;
return apply_filters('auth_cookie', $cookie, $user_id, $expiration);
}
endif;
if ( !function_exists('wp_set_auth_cookie') ) : if ( !function_exists('wp_set_auth_cookie') ) :
function wp_set_auth_cookie($user_id, $remember = false) { function wp_set_auth_cookie($user_id, $remember = false) {
$user = get_userdata($user_id); $user = get_userdata($user_id);
@ -368,10 +381,7 @@ function wp_set_auth_cookie($user_id, $remember = false) {
$expire = 0; $expire = 0;
} }
$key = wp_hash($user->user_login . $expiration); $cookie = wp_generate_auth_cookie($user_id, $expiration);
$hash = hash_hmac('md5', $user->user_login . $expiration, $key);
$cookie = $user->user_login . '|' . $expiration . '|' . $hash;
do_action('set_auth_cookie', $cookie, $expire); do_action('set_auth_cookie', $cookie, $expire);