SQL injection attacks

Source: Internet
Author: User
Tags sql injection sql injection prevention
SQL injection attacks

When you enter your account and password in the page, the password is set to ' or ' 1 ' = ' 1 o'clock, and when you enter the back-end server to query the information in the database, the query statement consists of:

SELECT * from Hhuser where nick= ' Zhangsan ' and passwords= ' or ' 1 ' = ' 1 ', the statement regardless of the user name and password can be found to meet the ' 1 ' = ' 1 ' condition, is the query user list is not empty. You can also use SQL attacks to cause irreversible disasters to your data. If you add ';d ROP table AAA after the password, the data table will be deleted.

SQL Injection Prevention

1. Use pre-compiled statements.

You can use the precompiled statement PreparedStatement to make a data query, execute the SQL statement through the statement object, send the SQL statement to the DBMS, and then execute it with the DBMS compiled. Precompiled instance:

String sql = "SELECT * from hhuser where Nick =?" and passwords =? ";

PreparedStatement st = conn.preparestatement (SQL);

St.setstring (1,nickname);

St.setstring (2,password);

ResultSet rs = St.executequery ();

2. Using ORM Framework

Use frameworks such as Ibatis, Hibernate, and so on, because these frames transfer keywords or special characters.

3, avoid password-free plaintext storage.

4, handle the exception of the response.

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.