TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 12-24-2009, 07:11 AM   #1 (permalink)
The Contributor
 
Join Date: Feb 2007
Posts: 64
Thanks: 9
Killswitch is on a distinguished road
Default Remember me login w/ cookies

Had a quick question. I have never messed with cookies before, but I know how they work. I am working on a user login and want to be able to use a remember me option, using cookies to do so.

I basically have it setup so I save the users id, username, password (salted and hashed), a unique token value and expiration in a cookie, and it is also saved in a database for lookup.

My question, is there any problem with storing a username and password in a cookie if the password is hashed and salted? The way I process the login, there is no sending of this value raw to the login methods. If so, the salted and hashed password in the cookie with be salted and hashed returning a different value.

Sorry for noobness with cookies, but never used this feature before.

Oh yea, also, when checking the cookies with what was entered in the database upon setting the cookie, I do it strictly. Every single piece of data must match or I remove the token information. I am also doing other small things such as checking the user agent and am using Kohana 2.4 session/cookie handling. Thanks.
Killswitch is offline  
Reply With Quote
Old 12-24-2009, 07:49 AM   #2 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

You should avoid putting the password into plain sight, especially when it's ultimately unnecessary - leave any critical information such as that (hashed or otherwise) stored behind a lock and key, and only use it when you need to.

It should be more than sufficient to store their user id, a session id (the unique token) and for a little extra security you can hash the user agent and store that too. In my own authentication script I hashed the ua with a random salt stored in the authentication table (similar to how the password was hashed) and concatenated the three values into a single string which was stored in the cookie.

The method that checked the authentication knew how to read the string and could split it up into its parts (don't use something like a seperator, if you're using a hash you should know the length of each value) and then run them against the data stored in the session table. This is just one way, there's a lot of others that work quite well. Just avoid putting the password out there into the world.
delayedinsanity is offline  
Reply With Quote
The Following User Says Thank You to delayedinsanity For This Useful Post:
Killswitch (12-24-2009)
Old 12-24-2009, 07:58 AM   #3 (permalink)
The Contributor
 
Join Date: Feb 2007
Posts: 64
Thanks: 9
Killswitch is on a distinguished road
Default

Ok I will look into it. I do also hash the user agent, I really didn't want anything in the cookie viewable but some information would be obvious. A user can easily find any users username and most of the time, their user id. I wasn't sure about the password but I don't think anyone could ever decrypt it since it's salted and ran through sha1. I will try to find a way around using the password in the cookie. Thanks.
Killswitch is offline  
Reply With Quote
Old 12-24-2009, 08:16 AM   #4 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Just don't use it at all. You don't need it in there - and chances are 99% of the script kiddiez out there who will attempt to break into your system won't have a clue what to do with a salted sha1, but why open the door for them? Lock the door, and then still hide your ice cream in the back of the freezer.
delayedinsanity is offline  
Reply With Quote
The Following User Says Thank You to delayedinsanity For This Useful Post:
Killswitch (12-24-2009)
Old 12-24-2009, 08:13 PM   #5 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

When validating users, use their unique database ID and a login key that you generate at login. This is how the login I wrote for a band worked.

1. User enters email and password
2. If they match, the script generates a login key (3/IGW4/?#6HW4 for example) and puts that and the users ID in seperate cookies. It also inserts these rows into the login table with the time.
3. Future pages validate based off of those two pieces of information in the login table.
4. After a certain amount of time of inactivity (we monitored every move made on the site) or if another log in takes place, the information in deactivated and kept for records.

This allowed us to see when users logged in and to log them out if we wanted to. It also provided security since the keys expired after a few minutes of inactivity, so having the login cookies would only work for a short time.
__________________

Village Idiot is offline  
Reply With Quote
The Following User Says Thank You to Village Idiot For This Useful Post:
Killswitch (12-24-2009)
Old 12-24-2009, 10:54 PM   #6 (permalink)
The Contributor
 
Join Date: Feb 2007
Posts: 64
Thanks: 9
Killswitch is on a distinguished road
Default

Thanks guys, this should get me finishing this up.
Killswitch is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to add remember me feature ? xgd General 7 01-29-2013 12:30 PM
SECURED REMEMBER ME Login praveenaj Advanced PHP Programming 1 02-12-2009 10:08 PM
How to Login to Any Account on an Insecure Site Wildhoney Tips & Tricks 18 12-14-2008 09:58 PM
user login page sarmenhb General 4 01-22-2008 09:33 AM
Highly secure login system ReSpawN Advanced PHP Programming 6 12-12-2007 08:28 PM


All times are GMT. The time now is 12:36 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design