Remember me button on login, fixes #379

git-svn-id: http://svn.automattic.com/wordpress/trunk@2733 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
matt 2005-07-23 06:56:59 +00:00
parent 7fb99dd853
commit 97a426b19c
2 changed files with 16 additions and 7 deletions

View File

@ -174,7 +174,7 @@ function wp_redirect($location) {
endif;
if ( !function_exists('wp_setcookie') ) :
function wp_setcookie($username, $password, $already_md5 = false, $home = '', $siteurl = '') {
function wp_setcookie($username, $password, $already_md5 = false, $home = '', $siteurl = '', $remember = false) {
if ( !$already_md5 )
$password = md5( md5($password) ); // Double hash the password in the cookie.
@ -191,12 +191,17 @@ function wp_setcookie($username, $password, $already_md5 = false, $home = '', $s
$cookiehash = md5($siteurl);
}
setcookie(USER_COOKIE, $username, time() + 31536000, $cookiepath, COOKIE_DOMAIN);
setcookie(PASS_COOKIE, $password, time() + 31536000, $cookiepath, COOKIE_DOMAIN);
if ( $remember )
$expire = time() + 31536000;
else
$expire = 0;
setcookie(USER_COOKIE, $username, $expire, $cookiepath, COOKIE_DOMAIN);
setcookie(PASS_COOKIE, $password, $expire, $cookiepath, COOKIE_DOMAIN);
if ( $cookiepath != $sitecookiepath ) {
setcookie(USER_COOKIE, $username, time() + 31536000, $sitecookiepath, COOKIE_DOMAIN);
setcookie(PASS_COOKIE, $password, time() + 31536000, $sitecookiepath, COOKIE_DOMAIN);
setcookie(USER_COOKIE, $username, $expire, $sitecookiepath, COOKIE_DOMAIN);
setcookie(PASS_COOKIE, $password, $expire, $sitecookiepath, COOKIE_DOMAIN);
}
}
endif;

View File

@ -163,6 +163,7 @@ default:
if( !empty($_POST) ) {
$user_login = $_POST['log'];
$user_pass = $_POST['pwd'];
$rememberme = $_POST['rememberme'];
$redirect_to = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $_POST['redirect_to']);
} elseif ( !empty($_COOKIE) ) {
if (! empty($_COOKIE[USER_COOKIE]) )
@ -182,8 +183,8 @@ default:
$redirect_to = get_settings('siteurl') . '/wp-admin/profile.php';
if ( wp_login($user_login, $user_pass, $using_cookie) ) {
if (! $using_cookie) {
wp_setcookie($user_login, $user_pass);
if ( !$using_cookie) {
wp_setcookie($user_login, $user_pass, false, '', '', $rememberme);
}
do_action('wp_login', $user_login);
wp_redirect($redirect_to);
@ -226,6 +227,9 @@ if ( $error )
<form name="loginform" id="loginform" action="wp-login.php" method="post">
<p><label><?php _e('Username:') ?><br /><input type="text" name="log" id="log" value="" size="20" tabindex="1" /></label></p>
<p><label><?php _e('Password:') ?><br /> <input type="password" name="pwd" id="pwd" value="" size="20" tabindex="2" /></label></p>
<p>
<label><input name="rememberme" type="checkbox" id="rememberme" value="forever" checked="checked" />
<?php _e('Remember me'); ?></label></p>
<p class="submit">
<input type="submit" name="submit" id="submit" value="<?php _e('Login'); ?> &raquo;" tabindex="3" />
<input type="hidden" name="redirect_to" value="<?php echo $redirect_to; ?>" />