Xaqron
Xaqron

Reputation: 30867

Randomness vs Uniqueness?

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 ?

Upvotes: 1

Views: 174

Answers (1)

Jakub Konecki
Jakub Konecki

Reputation: 46008

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

Upvotes: 2

Related Questions