ASP.NET自带的散列加密口令【转】
生活随笔
收集整理的這篇文章主要介紹了
ASP.NET自带的散列加密口令【转】
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
使用ASP.NET自帶類FormsAuthentication實現(xiàn)散列加密口令。
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");
????????????????//將用戶輸入的密碼哈希后再與數(shù)據(jù)庫是的哈希值進行比較
?????????? if(hash==myreader["password"]).ToString())
????????????????{
????????????????????????FormsAuthentication.RedirectFromLoginPage(UseridBox.Text,true);//轉(zhuǎn)到請求頁
?????????? }
????????????????else
????????????????????????Result.Text="密碼錯誤";
????????}
????????else
????????????????Result.Text="用戶不存在";
????????conn.Close();
}
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");
????????????????//將用戶輸入的密碼哈希后再與數(shù)據(jù)庫是的哈希值進行比較
?????????? if(hash==myreader["password"]).ToString())
????????????????{
????????????????????????FormsAuthentication.RedirectFromLoginPage(UseridBox.Text,true);//轉(zhuǎn)到請求頁
?????????? }
????????????????else
????????????????????????Result.Text="密碼錯誤";
????????}
????????else
????????????????Result.Text="用戶不存在";
????????conn.Close();
}
轉(zhuǎn)載于:https://www.cnblogs.com/myssh/archive/2009/05/31/1493190.html
總結(jié)
以上是生活随笔為你收集整理的ASP.NET自带的散列加密口令【转】的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 程序大腕
- 下一篇: 你人脉网中应该有的10种人