Should I use the username, or the user's ID to reference authenticated users in ASP.NET *

Question

So in my simple learning website, I use the built in ASP.NET authentication system.

I am adding now a user table to save stuff like his zip, DOB etc'. My question is:

  1. In the new table, should the key be the user name (the string) or the user ID which is that GUID looking number they use in the asp_ tables.
  2. If the best practice is to use that ugly guid, does anyone know how to get it? it seems to not be accessible as easily as the name (System.Web.HttpContext.Current.User.Identity.Name)
  3. If you suggest I use neither (not the guid nor the userName fields provided by ASP.NET authentication) then how do I do it with ASP.NET authentication? One option I like is to use the email address of the user as login, but how to I make ASP.NET authentication system use an email address instead of a user name? (or there is nothing to do there, it is just me deciding I "know" userName is actually an email address?

Please note:

  • I am not asking on how get a GUID in .NET, I am just referring to the userID column in the asp_ tables as guid.
  • The user name is unique in ASP.NET authentication

Answer

I would suggest using the username as the primary key in the table if the username is going to be unique, there are a few good reasons to do this:

  1. The primary key will be a clustered index and thus search for a users details via their username will be very quick.
  2. It will stop duplicate usernames from appearing
  3. You don't have to worry about using two different peices of information (username or guid)
  4. It will make writing code much easier because of not having to lookup two bits of information.
< br > via < a class="StackLink" href=" http://stackoverflow.com/questions/4911/" >Should I use the username, or the user's ID to reference authenticated users in ASP.NET< /a>
Share on Google Plus

About Cinema Guy

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment