在用户登录后,是否仍可以将数据库中的密码更改为MD5密码???
下面是我完成的代码的一部分:
using System.Security.Cryptography;
public static string pas;
public static string Password
{
get { return pas; }
set { pas = value; }
}
String str1 = "select * from user where username='" + textBox1.Text + "'
and pass='" + textBox2.Text + "'";
if (dr.Read())
{
Password = dr["pass"].ToString();
string anything = toMD5Hash(Password);
str1 = "INSERT INTO user (pass) VALUES ('" + anything + "');";
}
string toMD5Hash(string input)
{
//StringBuilder is used to collect the byte and collect a string
StringBuilder sb = new StringBuilder();
using (MD5 md5 = MD5.Create())
{
byte[] data = md5.ComputeHash(Encoding.UTF8.GetBytes(input));
for (int i = 0; i < data.Length; i++)
{
sb.Append(data[i].ToString("x2")); //Print byte to
hexadecimal
}
}
return sb.ToString();
}
是的,我知道MD5有点薄弱,我只是想尝试
已更新: 错误不再显示,我可以登录,但是数据库密码仍然没有更改为MD5格式 nvm,我自己解决了阿迪