ASP.NET裏面散列加密口令

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();
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章