Hashing verschlüsselter Passwörter in ASP.NET
Autor:Eve Cole
Aktualisierungszeit:2009-06-30 16:44:17
private void LoginButton_Click(object sender,System.EventArgs e)
{
String sql=String.Format("Passwort vom Administrator auswählen, wobei AdminID='{0}',UseridBox.Text);
SqlConnection conn=new SqlConnection(ConfigurationSettings.AppSettings["connectionString"]);
SqlDataReader myreader=new SqlCommand(sql,conn).ExecuteReader();
if(myreader.Read())
{
String hashed=FormsAuthentication.HashPasswordForStoringInConfigFile(PasswordTextBox.Text,"SHA1");
//将用户输入的密码哈希后再与数据库是的哈希值进行比较
if(hash==myreader["password"]).ToString())
{
FormsAuthentication.RedirectFromLoginPage(UseridBox.Text,true);//转到请求页
}
anders
Result.Text="密码错误";
}
anders
Result.Text="用户不存在";
conn.Close();
}