In Asp.net, we strongly recommend that you concatenate SQL statements instead of SQL statements using parameters.

Source: Internet
Author: User
Tags common sql injection attacks sql injection attack

In Asp.net, we strongly recommend that you use parameters to implement SQL statements instead of SQL concatenation, because even if you filter hundreds of passwords
For example:

Sqlconnection conn = new sqlconnection (system. configuration. configurationsettings. deleettings ["conn"]);
Sqlcommand comm = new sqlcommand ("Update tb1 set vname = @ vname, iage = @ iage where id = @ ID", Conn );
Sqlparameter parm1 = new sqlparameter ("@ vname", sqldbtype. nvarchar, 50 );
Parm1.value = (textbox) E. Item. findcontrol ("name"). text;
Sqlparameter parm2 = new sqlparameter ("@ iage", sqldbtype. INT );
Parm2.value = (textbox) E. Item. findcontrol ("Age"). text;
Sqlparameter parm3 = new sqlparameter ("@ ID", sqldbtype. INT );
Parm3.value = This. datagrid1.datakeys [E. Item. itemindex];
Comm. Parameters. Add (parm1 );
Comm. Parameters. Add (parm2 );
Comm. Parameters. Add (parm3 );
Conn. open ();
Comm. executenonquery ();
Conn. Close ();

This code looks comfortable and safe. Why?

 

The so-called SQL injection attack means that an attacker inserts an SQL command into the input field of a web form or the query string requested by the page, and deceives the server to execute malicious SQL commands. In some forms, the content entered by users is directly used to construct (or affect) dynamic SQL commands or as input parameters of stored procedures. Such forms are particularly vulnerable to SQL injection attacks. Common SQL injection attacks include:

(1) An ASP. NET web application has a logon page that controls whether the user has the right to access the application. It requires the user to enter a name and password.

(2) The content entered on the logon page is directly used to construct dynamic SQL commands, or directly used as parameters of stored procedures. The following is an example of constructing a query for an ASP. NET application:

System. Text. stringbuilder query = new system. Text. stringbuilder (

Select * from users where login =)

. Append (txtlogin. Text). append (and Password =)

. Append (txtpassword. Text). append ();

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.