我有一個登錄頁面,其中我已經編寫代碼來登錄管理部分,但它不工作我不知道什麼問題是這個代碼是正確的仍然未經授權的訪問。幫我出登錄頁面錯誤在asp.net c#
string str = ConfigurationManager.ConnectionStrings["ottscon"].ConnectionString;
using (SqlConnection con = new SqlConnection(str))
{
SqlCommand cmd = new SqlCommand("Select UserName,Password from login where [email protected] and [email protected]", con);
con.Open();
cmd.Parameters.AddWithValue("@userid", TextBox1.ToString());
cmd.Parameters.AddWithValue("@passid", TextBox2.ToString());
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds= new DataSet();
da.Fill(ds);
if (ds.Tables[0].Rows.Count>0)
{
Session["login"] = TextBox1.Text;
Response.Redirect("admintrator123/Default.aspx");
}
else
{
Label1.Text = "Unauthorized Access";
Label1.ForeColor = System.Drawing.Color.Red;
}
}
你存儲密碼以純文本形式? – Kamo
是作爲純文本 – shashank
這有點危險,你應該考慮以散列的形式存儲它們。當你直接在數據庫上執行查詢時,你得到的參數會得到任何結果? – Kamo