Search code examples
asp.netsqlcookiesauthenticationdatabase-driven

How to create a database driven login system


I want to create a website that the login system shouldn't be handled by cookies, but on (a) table(s) in the local (on the server) SQL DB.

Is there a way to do it? Even no partial way?

What and where should I save instead of the cookie???


Solution

  • ASP.NET uses Session cookies by default to track user requests. If you use Cookieless sessions, you will find the Session ID being appended in all requests from the browser. In many scenarios, this could also be unacceptable.

    Even if you decide to hit the database and check for a "LoggedIn" flag upon each request, you still need some way to identify the incoming request as belonging to a particular user. This could be in the form of encrypted values in hidden fields, depending on your security scenario. That said, it's not a much better method than the use of cookies, because any data that comes from the client has the potential to have been tampered with.

    Personally, I think Cookies are great to track user requests as long as you encrypt them properly.