scriptygoddess

01 Jul, 2004

Add a "remember me" checkbox to the login form

Posted by: Jennifer In: WordPress Hacks

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

13 Responses to "Add a "remember me" checkbox to the login form"

1 | Neil Stead

July 1st, 2004 at 3:34 am

Avatar

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!).

2 | Mark J

July 1st, 2004 at 4:03 am

Avatar

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!

3 | Carthik

July 1st, 2004 at 12:31 pm

Avatar

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.

4 | david

July 1st, 2004 at 3:02 pm

Avatar

Aha I finely figured it out :)

5 | Code Novice

July 1st, 2004 at 4:10 pm

Avatar

Bookmarks: MT, WP and Moneymaking Blogs
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 …

6 | Andrew

July 6th, 2004 at 8:10 pm

Avatar

I'm glad my comment about passing NULL could be useful.

7 | Mama Write

July 7th, 2004 at 8:01 pm

Avatar

Various WordPress Links
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…

9 | Neil Stead

July 30th, 2004 at 12:59 pm

Avatar

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.

10 | Tin

August 16th, 2004 at 3:27 pm

Avatar

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.

11 | Stacey

November 4th, 2004 at 9:18 am

Avatar

Is there a way to make a "remember me" option for comments?

For some reason it isn't working on my site.

12 | james

November 11th, 2004 at 6:50 pm

Avatar

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!

13 | Remember Me for logins : [ mkhairul.com ]

September 18th, 2007 at 9:48 pm

Avatar

[…] Scriptygoddess – Add a remember me checkbox to the login form […]

Featured Sponsors

Genesis Framework for WordPress

Advertise Here


  • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
  • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
  • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

About


Advertisements