使用ASP.NET自带类FormsAuthentication实现散列加密口令。
private void LoginButton_Click(object sender,System.EventArgs e)
{
        String sql=String.Format("select password from Administrator where 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);//转到请求页
           }
                else
                        Result.Text="密码错误";
        }
        else
                Result.Text="用户不存在";
        conn.Close();
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-20
  • 2022-02-22
  • 2022-12-23
  • 2022-01-25
猜你喜欢
  • 2021-12-16
  • 2021-11-01
  • 2022-12-23
  • 2021-09-27
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案