asp.net authentication

C# Generate Password Hash with Salt

There are many options to store passwords in a database for authenticating users. One of the more secure methods is to store a one-way "hash" of the password instead of the password itself. Another option is to encrypt the password and store it in its encrypted form in the database. There are benefits and drawbacks to both approaches.

Password Hashing Benefits

  • If an attacker gains access to your database, they cannot retrieve the passwords of your users because they are one-way hashed (meaning that you can't back the hash back out to its original string form)

ASP.NET Forms Authentication Simplified

There are so many tutorials online about Forms Authentication or other auth methods in ASP.NET that it is sometimes hard to wade through and get what you need. I've made a very simple wrapper class that you can include in your ASP.NET project to give you out of the box, basic forms authentication.

Get Authentication Mode from Web.Config file

If you want to find out programmatically what authentication mode the current ASP.NET website is running under you can actually read it from the web.config file using the code below.

System.Web.Configuration.AuthenticationSection section = 
    (System.Web.Configuration.AuthenticationSection)System.Web.Configuration.WebConfigurationManager.GetSection("system.web/authentication");