Creating ASP.NET Forms Authentication Credentials

07 Dec 2009

On a recent project, I needed to quickly create a password to use with ASP.NET Form Authentication. I got tired of typing my full user name.

I quickly hacked the following:

using System;
using System.Web.Security;
public class Sha1Str
{
    public static void Main(string[] args)
    {
        if (args.Length > 0) {
            string pass = FormsAuthentication
				.HashPasswordForStoringInConfigFile(args[0], "sha1");
            Console.WriteLine(pass.ToLower());
        }
    }
}

After compiling and running at the console, I could get the password string:

% Sha1Str me
b1c1d8736f20db3fb6c1c66bb1455ed43909f0d8

The only thing left was to add it to the web.config:

<user name="me"
	password="b1c1d8736f20db3fb6c1c66bb1455ed43909f0d8" />