views:

1811

answers:

5

I've got an existing site I'm taking over, and right now it stores, in a session variable, the id of the currently logged in user (if logged in at all -- otherwise I'm sure it is empty string or null or something).

The client now wants, after someone is logged in, to "keep" them logged in on that computer for an indefinite amount of time.

ASP.net Sessions have a maximum idle time of 1 day, I believe. The website isn't written all that well in the Flash portion (whole front end is flash) and the flash will process a login, then, as long as the flash isn't reloaded, assume that the user is still "logged in".

I think my solution is to ALSO store a client side cookie with some GUID value and hold in the database the associated user id...sort of like a session that never expires. So, when the page is loaded, I can check my cookie, use that to select the userid out of the database, and if we find one, then set the session value that says user 23 is logged in.

Does anyone see any issues with this perspective? Would you recommend something different? I really don't want to refactor a bunch of the existing code, but just slip this in on top...

PS -- security is not really a concern. The only reason they have people log in is so we can track orders by a person, but no money changes hands through this website. There is also no personal information that a user can view or edit, either.

+1  A: 

This is how I do it. I actually have a cookie that holds their login and password, this way I can automatically log them in should they not be logged in. I expire the cookie after a couple of days of inactivity. The downside is that everyone forgets their password because the only time they really have to enter their password is when they come back from extended time-off.

This is for an internal application, with the same customer demands that you have and this works ... and makes the customer happy.

One thing we may end up doing is just using Windows authenication, might actually work better in this circumstance.

mattruma
Our users aren't on the same network, so Network Auth isn't an option here, but thanks for the advice. I'm going to store a guid in a cookie (instead of the username/password like you do) and look it up. Seems like we are on the same page. Thanks!
Matt Dawdy
Excellent! For whatever it is worth I do encrypt the cookie values.
mattruma
LOL! Yeah, even though it wouldn't matter, it just KILLS me to store usernames and passwords in plain text. I WILL do what you recommend then -- store username/password all encrypted client side in a cookie. No DB changes that way. Thanks again.
Matt Dawdy
Encrypted or not, storing the username and/or password client-side in a cookie is just bad form, IMHO.
WaldenL
A: 

That's the way I do it, but the problem with it (at least I think its a problem) is that when you store the username and password in a cookie there is not any encrypting when you add the cookie. If you look at the cookies in your browser the username and password are displayed there plain as day. Is it possible to get some kind of encrypting on the cookies you store? Or how would you handle this?

hanesjw
As I read the thread, I realize it's not that clear. What I meant was that, server side, I encrypt the username/password and then send that encrypted value as the cookie. On a subsequent request, I receive the encrypted value and decrypt it, server side. Nothing in clear text on client side.
Matt Dawdy
A: 

Check this blog posting out http://timmaxey.net/archive/2009/03/06/asp.net-cookie-auto-log-in.aspx basically you needs to save the cookie with a guid a series, and a token, the token, in my case, changes all the time, the series is something that is generated based on something, like the guid and id combo or whatever, then the guid is always stored with the user. There is a cookie table to stored this info etc... pretty secure, not 100%, but pretty good... Tim Maxey

A: 

I recommend using the Enterprise Library Crypto App Block to store an encrypted cookie which is nothing more than a GUID. Get the GUID, and use a session table in the database to track user info.

At the session start event, get the user info and cache it.

Using the session object is not recommend for user info because it won't work on a web farm, unless you use a database for session state.

A: 

You're basically rolling your own session state at that point, and I'm fine with that. However, I would not go the route of storing the username/password in a cookie (even if encrypted). There's no way to expire that from the server-side. You can always remove your row in the table to force a user to log in again, but if they hold the username/password they hold the keys to the kingdom.

WaldenL