我有表user_info創建,並在其中有2個用戶名和密碼。 當我執行下面的代碼時,即使我輸入正確的用戶名和密碼,它也會進入「其他」狀態。登錄身份驗證邏輯不工作在C#.NET
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
string v = System.Configuration.ConfigurationManager.ConnectionStrings["harish"].ConnectionString;
con = new OracleConnection(v);
con.Open();
cmd = new OracleCommand("select * from user_info where username='" + Login1.UserName.Trim() + "' and password='" + Login1.Password + "'", con);
dr = cmd.ExecuteReader();
dr.Read();
if (dr.HasRows)
{
Response.Redirect("Default2.aspx");
}
else
{
Response.Redirect("Default.aspx");
}
con.Close();
dr.Close();
}
**不要在密碼文本中存儲密碼** – SLaks
您有一個SQL注入漏洞。 – SLaks
其他人指出的問題很多。但是,您需要插入一個斷點,在ExecuteReader處中斷並查看實際值。您也可以直接對Oracle運行生成的查詢,以確保它是正確的。 –