我已在用戶通過前端登錄的應用程序的後端創建了以下WebMethod
。拆分用戶名和密碼憑證
[WebMethod]
public String Login(String userName, String password)
{
OleDbConnection connect = new OleDbConnection(connection);
connect.Open();
OleDbCommand command = new OleDbCommand("Select * from login where userName='" + userName + "' and password ='" + password + "'", connect);
command.CommandType = CommandType.Text;
OleDbDataAdapter adapter = new OleDbDataAdapter();
adapter.SelectCommand = command;
DataSet NSNSet = new DataSet();
adapter.Fill(NSNSet);
string username = NSNSet.Tables[0].Rows[0]["firstName"].ToString() + NSNSet.Tables[0].Rows[0]["lastName"].ToString();
int userID = System.Convert.ToInt16(NSNSet.Tables[0].Rows[0]["UID"].ToString());
return username + "," + userID;
}
目前,我有錯誤處理以代替陳述 -
catch(Exception ex)
{
string error = System.Convert.ToString(ex);
if (error.Contains("There is no row at position 0"))
{
status.Text = "Incorrect Username/Password combination";
}
}
這工作得很好,但我怎麼可能aulter我的代碼,以便它帶回一個更具體的錯誤,即國家如果userName
或password
具體是不正確的?
問題1:打開sql注入;問題2:密碼似乎以純文本形式存儲;問題3:檢查「無記錄」 *之前*您訪問的行0 –
通常,你不想給比「無效組合」更多詳細資料(OK,這樣的「管理員」賬戶存在現在讓我們嘗試輸入密碼?!) –