SQL statement Password Authentication security vulnerabilities

Source: Internet
Author: User

SQL statements, as the International Standard database query statements, have been widely used in various programming environments. As a mature and stable system, user login and password verification is essential. The author in peacetime programming work found that many programmers in SQL statements for user password verification is a similar statement to achieve:

Sql= "SELECT * from user table where name = ' +name+" ' and password = ' +password+ ' "

Where name and password are the username and password that the user entered, verify that the user and password are legitimate and valid by executing the above statement. But through the analysis, it can be found that the above statement has a fatal loophole. When we enter the following string in the user name: 1=1 ' or ', and then enter the password casually, we set to AAAA. When a variable is substituted, the SQL statement becomes the following string:

Sql= "SELECT * from user table where name = ' $ ' or ' 1=1 ' and password = ' aaaa '

We all know that when a SELECT statement determines a query condition, the encounter or operation ignores the following and (and) actions, whereas the 1=1 value in the above statement is always true, meaning that no matter what value is entered in the password, it can be authenticated by the password above! The solution to this problem is very simple, there are many methods, the most commonly used in the implementation of authentication before the user entered the user and password for the legality of judgment, do not allow the input single quotes, equal signs and other special characters.

The above question, though seemingly simple, does exist. For example, on the Internet is very famous online game "laughing Proud" of the early version of the existence of such a problem, the author is also looking at the vulnerability of the game report after careful analysis of their previous written procedures, even a lot of such loopholes exist. This really ought to attract our attention. It also exposes the lack of programming experience and security awareness among young programmers, including the author. At the same time, we also remind programmers in the program design should fully consider the security of the program, there should be no careless, a seemingly small omission may cause very serious consequences.

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.