How to prevent SQL injection attacks

Source: Internet
Author: User
Tags how to prevent sql injection how to prevent sql injection attacks sql injection

Suppose SQL is an article that searches for user A, SQL would look like this:

SELECT * FROM table where owner= ' A ';

SQL injection attackers modify user names to implement attacks, such as changing A to a ' or 1 = ' 1

The combined SQL statement:

SELECT * FROM table where owner= ' A ' or 1 = ' 1 ';

This will allow you to get all the user's articles

It can be seen that the SQL attack is to falsify part of the data content into SQL statements, such as the above or 1 = forged into SQL statements to implement the attack

The forgery method is to add quotation marks to the content, so the method of preventing SQL injection is to escape the quotes inside the parameters, for example, to change the user name to A\ ' or 1=\ ' 1 to prevent such a SQL attack

Quotation marks include single and double quotation marks

Python's MySQLdb module has a specially escaped function:

Import MySQLdb def Safe (s):     return Mysqldb.escape_string (s)

How to prevent SQL injection attacks

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.