I’m wanting to change our c# asp.net mvc application to work with windows authentication as well as forms authentication (as is currently implemented).
Currently we have a number of tables referencing a user id integer in the user table used by the forms authentication.
Is there an appropriate way of converting the unique string username returned by windows authentication to a unique integer that can be used as the id for the other tables?
An example might be using .GetHashCode() on the username, however I’m not sure if that will definitely create an appropriate integer (ie. unique, always the same integer returned given the same username, etc.)
GetHashCode() changes between framework versions, OS platform, etc., so you cannot rely on it for use as a DB PK.
If you are working with Windows authentication then maintaining the identify is useful for debugging, troubleshooting and possibly impersonation. Why not store it in a table with a Windows Username -> UserID mappings so that you can lookup a User ID given a user name?