萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> asp.net編程 >> ASP.NET中散列加密密碼

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();

  }

copyright © 萬盛學電腦網 all rights reserved