//添加引用
//using System.Text;
//using System.Security.Cryptography;
//密码加密算法流程
//将密码按以下方式加密之后,存进数据库
//在验证用户身份时再加密码加密和数据库密码进行比较
//using System.Text;
//using System.Security.Cryptography;
//密码加密算法流程
//将密码按以下方式加密之后,存进数据库
//在验证用户身份时再加密码加密和数据库密码进行比较
public string Encrypt(string password)
{
password = password.ToLower();
Byte[] clearBytes = new UnicodeEncoding().GetBytes(password);
Byte[] hashedBytes = ((HashAlgorithm) CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes);
return BitConverter.ToString(hashedBytes);
}
另一种和asp生成值一样的代码:
{
password = password.ToLower();
Byte[] clearBytes = new UnicodeEncoding().GetBytes(password);
Byte[] hashedBytes = ((HashAlgorithm) CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes);
return BitConverter.ToString(hashedBytes);
}
另一种和asp生成值一样的代码:
protected string UserMd5(string str)
{
byte[] result = Encoding.Default.GetBytes(str);
MD5 md5 = new MD5CryptoServiceProvider();
byte[] output = md5.ComputeHash(result);
return BitConverter.ToString(output).Replace("-", "");
}
{
byte[] result = Encoding.Default.GetBytes(str);
MD5 md5 = new MD5CryptoServiceProvider();
byte[] output = md5.ComputeHash(result);
return BitConverter.ToString(output).Replace("-", "");
}