Tuesday, January 5, 2010

Best hashing password techniques in C#

The following post will lead you through storing a password value which will be salted and hashed and then stored in your sql server database

For ref see http://stackoverflow.com/questions/615704/preferred-method-of-storing-passwords-in-database

C# to convert password value to hash value which would be stored in database:

using System;


 string EncodePassword(string originalPassword)
  Byte[] originalBytes;
  Byte[] encodedBytes;
  MD5 md5;

  //Instantiate MD5CryptoServiceProvider, get bytes for original password and compute hash (encoded password)
  md5 = new
  originalBytes = ASCIIEncoding.Default.GetBytes(originalPassword);
  encodedBytes = md5.ComputeHash(originalBytes);

  //Convert encoded bytes back to a 'readable' string

No comments:

Post a Comment