views:

90

answers:

1

Does the original data type of the username string in a call to FormsAuthentication.SetAuthCookie(...) make any difference with regards to security or code maintainability?

As I understand it, the cookie is encrypted and used to identify a user on each request. I'm curious whether it should affect the design of the primary key on my Users table in my database, eg. Guid vs int or a unique username string.

+4  A: 

FormsAuthentication.SetAuthCookie has no knowledge of your key. It expects a Username, which is the lingua franca for most all interop between the ASP.Net providers.

So, No, your key could be a 10mb blob and you would still pass the Username, which is typically a human readable string, to FormsAuthentication.SetAuthCookie.

What I am getting at is that the UserId is not stored in the auth ticket so the data type or size of the UserId has no effect on the auth ticket cookie.

Sky Sanders
+1 for `your key could be a 10mb blob` :-)
Darin Dimitrov
Thanks for your answer, Sky. If the UserId is not stored in the cookie, then I presume the ticket must contain it somewhere, but then where is the ticket containing the UserId stored? I use Guid UserId = new Guid(System.Web.HttpContext.Current.User.Identity.Name); - don't know if it's best practice.
FreshCode
@freshcode - ticket==cookie. same thing. The UserId is not passed or stored in ANY cookie. The UserName is stored in the cookie. This is the 'natural key', and is used to get the user when necessary, where the UserId, which is a surrogate key can be found.
Sky Sanders

related questions