本文共 1094 字,大约阅读时间需要 3 分钟。
protected void Login_Click(object sender, EventArgs e) { using(SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString)) { con.Open(); SqlCommand cmd = new SqlCommand(); cmd.CommandText = "SELECT Count(1) FROM [User] where UserName='" + TBU.Text.Trim() + "' and Password='" + TBP.Text.Trim() + "'"; cmd.CommandType = CommandType.Text; cmd.Connection = con; int count =(int) cmd.ExecuteScalar(); Response.Write(cmd.CommandText); if (count > 0) { Response.Write(""); } else { Response.Write(""); } } }
用户名输入:test' or ''='
密码输入:' or ''='
或者
用户名输入:test
密码输入:' or ''='
如图:
其他ASP.net SQL注入的例子,如果有兴趣可以参考下:
其他的SQL注入: