How to encrypt password or data in c#Using the small function, you can encrypt the password and store it in database and again when you need to compare the password, encrypt the password again that user typed and compare with previouly encrypted password.
Here is the code:
using System.Text;
using System.Security.Cryptography;
public static string EncryptPassword(string strPassword)
{
MD5CryptoServiceProvider p = new MD5CryptoServiceProvider();
byte[] arr = Encoding.UTF8.GetBytes(strPassword);
arr = p.ComputeHash(arr);
StringBuilder sb = new StringBuilder();
foreach (byte b in arr)
{
sb.Append(b.ToString("x2").ToLower());
}
return sb.ToString();
}
Happy Coding...