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;
using System.Text;
using System.Security.Cryptography;
...
public string EncodePassword(string originalPassword)
{
//Declarations
Byte[] originalBytes;
Byte[] encodedBytes;
MD5 md5;
//Instantiate MD5CryptoServiceProvider, get bytes for original password and compute hash (encoded password)
md5 = new MD5CryptoServiceProvider();
originalBytes = ASCIIEncoding.Default.GetBytes(originalPassword);
encodedBytes = md5.ComputeHash(originalBytes);
//Convert encoded bytes back to a 'readable' string
return BitConverter.ToString(encodedBytes);
}
No comments:
Post a Comment