views:

48

answers:

1

In a web application if a user check the Remember Me box I'm gonna create a cookie and save it in database and assign it to user (long-life cookie). On any page request (page_load) I check this cookie (if session is null) and ask DAL for user object. If I use GUID it would be unique but the question is if a user can guess the pattern maybe he could cheat by sending a hand-made cookie. What is the best practice (C# sample) for creating such a text to be random enough ?

+1  A: 

You can use FormsAuthentication.SetAuthCookie method (even if you don't use Forms authentication). There's no point in reinventing the wheel ;-)

Jakub Konecki
Then how to retrieve it and store it in database ?
Xaqron
By calling FormsAuthentication.GetAuthCookie. Or better use ASP.NET session id (HttpContext.Current.Session.SessionID)
Jakub Konecki