« AssemblyVersion equals build time | Main | ASP.NET, Event Log Access, Creating new category entries in HKLM »

MD5 Password Hash Pattern

Here's a little code snippet that hashes the plain-text customer password for storage in a database table:

 

sqlConnection.Open();

SqlCommand cmd = sqlCmdCustomerAdd;

cmd.Parameters["@guid"].Value = Guid.NewGuid();

cmd.Parameters["@email"].Value = tbEmail.Text;

byte[] passwordBytes = System.Text.Encoding.UTF8.GetBytes(tbPassword.Text);   

byte[] passwordHash = ((HashAlgorithm) CryptoConfig.CreateFromName("MD5")).ComputeHash(passwordBytes);

cmd.Parameters["@password"].Value = Convert.ToBase64String(passwordHash);

cmd.ExecuteNonQuery();

sqlConnection.Close();

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)