示例
为了更好了学习和了解SQL注入的方法,做了一个示例网页,界面如下:
点击登陆这块的代码如下,注意第5行,我们使用了拼接SQL语句:
复制代码 代码如下:
private void Login()
{
string uname = tbName.Text;
string pwd = tbPassword.Text;
string sqlCmd = "select * from [Users] where UserName = '" + uname + "'";
string sqlCmdRep = sqlCmd.Replace("Users", "XXX").Replace("UserName", "XXX");
lbSQL.Text = sqlCmdRep;
try
{
DataTable dt = DataSQLServer.GetDataTable(sqlCmd);
gvResult.DataSource = dt;
gvResult.DataBind();
if (dt.Rows.Count == 1 && pwd == dt.Rows[0]["Password"].ToString())
{
lbRes.Text = dt.Rows[0]["UserName"] + " Login Success!";
}
else if(dt.Rows.Count == 0)
{
lbRes.Text = uname + " not exist!";
}
else
{
lbRes.Text = "Login Fail!";
}
}
catch (Exception ex)
{
lbRes.Text = "Error: " + ex.Message;
}
}
当前1/3页123下一页阅读全文