Add a "remember me" checkbox to the login form
Neil had asked about adding a "remember me" checkbox to the login form. The idea here is that if you're really forgetful (like me! Ack!) and you know you're really forgetful - and you know you're probably going to forget to "logout" before closing your browser - if you don't click the "remember me" checkbox - then when you close your browser, you will be automatically logged out of WordPress. (This is good when you're working on a shared computer)
It does require some core WP editing - minor tweaks to just the wp-login.php page - but wanted to warn you up front (I have to apologize for the core edits. I'm more than welcome to hear suggestions of how one can do this WITHOUT doing the core editing - but I just can't come up with it)
Open up wp-login.php. Look for the following codes (should be on lines 389 and 391) :
setcookie('wordpressuser_'.$cookiehash, $user_login, time() + 31536000, COOKIEPATH);
setcookie('wordpresspass_'.$cookiehash, md5($user_pass), time() + 31536000, COOKIEPATH);
and replace those two lines with the following:
if (isset($_POST['rememberme'])) {
setcookie('wordpressuser_'.$cookiehash, $user_login, time() + 31536000, COOKIEPATH);
setcookie('wordpresspass_'.$cookiehash, md5($user_pass), time() + 31536000, COOKIEPATH);
} else {
setcookie('wordpressuser_'.$cookiehash, $user_login, NULL, COOKIEPATH);
setcookie('wordpresspass_'.$cookiehash, md5($user_pass), NULL, COOKIEPATH);
}
(Passing "NULL" suggestion by Andrew in the comments thread) Then look for what will now probably be on line 313:
<p><label><?php _e('Password:') ?> <input type="password" name="pwd" value="" size="20" tabindex="2" /></label></p>
And add this just below it
<p><label>Remember me? <input type="checkbox" name="rememberme" value="rememberme" tabindex="3"></label></p>
Then, if you want to be "auto-logged-out" when you close your browser, just make sure you DON'T click that "remember me" checkbox
Post updated 10/7/2004 to reflect changes in WP 1.2.1
July 1st, 2004 at 3:34 am
Jennifer, you're just a marvel! Only asked for this yesterday, and here it is already! I look forward to trying it out - Thanks!
(NB: My URI points to my club's current website - for a look at how I'm changing it to use WP, have a look at the new site - very much under construction!).
July 1st, 2004 at 4:03 am
Jenn,
I'm almost positive that there is currently no way to do this with a plugin.
Even if you could harness a hook to set a cookie, I've only run into trouble when trying to set the same cookie multiple times in the same script execution.
Of course, you COULD just offer the modified wp-login.php for download. Heck, that's easier than a plugin, because you don't have to go in and activate it!
July 1st, 2004 at 12:31 pm
I have seen this request a few times over at the forums. Maybe you can send a diff to matt so he can think of including it.
July 1st, 2004 at 3:02 pm
Aha I finely figured it out
July 1st, 2004 at 4:10 pm
Scriptygoddess continues to post numerous WP-related fixer-uppers with three new offerings:
Adding content to the spam list
Delete all comments via moderation
Add a 'remember me' option on login page
David Raynes posted his latest MT …
July 6th, 2004 at 8:10 pm
I'm glad my comment about passing NULL could be useful.
July 7th, 2004 at 8:01 pm
Rather than ping ScriptyGoddess multiple times and clog my sideblog with even more WordPress links, I decided to plop 'em all here. I'm going to give WordPress a try again on my course website, since there are various hacks that…
July 14th, 2004 at 10:04 am
thanks!
July 30th, 2004 at 12:59 pm
Just discovered that if a user changes their password, WP sets the cookie for the new password - so that it will always be remembered.
I think the easiest solution is to change the code in profile.php so that it just sets a session cookie - the user will have to log back in next time he comes to the site.
Replace:
setcookie('wordpresspass_'.$cookiehash, md5(md5($newuser_pass)), time() + 31536000, COOKIEPATH);
with
setcookie('wordpresspass_'.$cookiehash, md5(md5($newuser_pass)), NULL, COOKIEPATH);
There may be a more elegant way of doing this - by finding out the current expiry date of the cookie, for example, but I don't know how.
Neil.
August 16th, 2004 at 3:27 pm
hi. for some reason this doesnt work for me. everything runs smoothly but when i close my browser and reopen it, i'm still logged in. i followed all your directions closely. do you have a wp-login.php already prepared so i can download? i'm wondering if i did something wrong with the modifications.
November 4th, 2004 at 9:18 am
Is there a way to make a "remember me" option for comments?
For some reason it isn't working on my site.
November 11th, 2004 at 6:50 pm
I am in the same boat as Tin.
I modified the code and nothing changed. Everything still works fine, but I am still permanently logged in even after I close my browser.
I am using worpress 1.2.1
Any ideas? It would be nice to see a full wp-login.php file from somebody who has managed to make it work.
This would be great, if I could get it working.
Thanks!
September 18th, 2007 at 9:48 pm
[...] Scriptygoddess - Add a remember me checkbox to the login form [...]