static string HashPasswordForStoringInConfigFile (string password, FormsAuthPasswordFormat passwordFormat)
{
if (password == null)
throw new ArgumentNullException ("password");
byte [] bytes;
switch (passwordFormat) {
case FormsAuthPasswordFormat.MD5:
bytes = MD5.Create ().ComputeHash (Encoding.UTF8.GetBytes (password));
break;
case FormsAuthPasswordFormat.SHA1:
bytes = SHA1.Create ().ComputeHash (Encoding.UTF8.GetBytes (password));
break;
default:
throw new ArgumentException ("The format must be either MD5 or SHA1", "passwordFormat");
}
return MachineKeySectionUtils.GetHexString (bytes);
}