About SQL injection

Source: Internet
Author: User
Tags sql injection table name
There are 5 misunderstandings:
1, SQL injection is more difficult to prevent, you need to replace select,delete, such as a typing character
In fact, no more than the replacement of character type single quotes for two single quotes good! There is no use for any number of replacements, so be sure to type conversions.
2, ignore the things that DropDownList came
In fact, all the client's things are not trustworthy, select the dropdown box is also! Because you can make an HTM submission to the server yourself.
3. Access is less secure than SQL Server
Security unsafe key See how to use, if SQL Server is still used like access, a sa account, it is clear that SQL Server is less secure than access, you can get the table name and field name directly! Access turns out to be safe, because it can only be obtained by a bitwise guess.
4, the website does not display the error message to explain the website is safe
When there are records to show the record, there is no record when the display can not find any records, through these two states will be able to guess the name of the field, so the Web page error can not be explained is safe
5. Ignore Post submitted information
A lot of people on the URL to pass on the things that are strictly filtered, for post things to ignore is wrong, post things more easily injected, because the general field more

In ASP.net, it is strongly recommended that you implement SQL instead of SQL concatenation by using parameters, because even if you filter each of the hundred difficult to have sparse
Like what:

SqlConnection conn=new SqlConnection (system.configuration.configurationsettings.appsettings["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 ();


So the code looks comfortable and safe, he le?




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.