in few of lines of code,
1. how can i hash a strPasswd, and
2. compare it to see if it matches a textbox value
(when user enters password, it will be compared to the hash in the db)
Printable View
in few of lines of code,
1. how can i hash a strPasswd, and
2. compare it to see if it matches a textbox value
(when user enters password, it will be compared to the hash in the db)
Try using the following method which uses the MD5 algorithm. You need to reference the System.Security.Cryptography namespace.
Basically pass in a string and it will return the hash in a string format.Code:public static string Encrypt(string cleanString)
{
Byte[] clearBytes = new UnicodeEncoding().GetBytes(cleanString);
Byte[] hashedBytes = ((HashAlgorithm) CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes);
return BitConverter.ToString(hashedBytes);
}
HTH
DJ