When PHP web applications are injected, how does one write user logon to prevent bypass login through injection?

Source: Internet
Author: User
When PHP web applications are injected, how to write user logon to prevent bypass login through injection is assumed that the conditions cannot be changed. do not reply to prevent injection in general 2: 1 $ SQL & quot; select * fromuserwhereuser_name $ usernameandpassword $ password & quot; $ res... how to write user logon when PHP web applications are injected to prevent bypass login through injection

If the conditions cannot be changed, do not reply to prevent injection.

2 in general
·
1
$ SQL = "select * from user where user_name = $ username and password = $ password ";
$ Res = $ db_obj-> get_one ($ SQL );
If ($ res ){
// Login successful
}
·
·
2
$ SQL = "select * from user where user_name = $ username ";
$ Res = $ db_obj-> get_one ($ SQL );
If ($ res [password] = md5 ($ password )){
// Login successful
}
·
Any of the above two can be bypassed to seek security

Reply content:

How to write user logon when PHP web applications are injected to prevent bypass login through injection

If the conditions cannot be changed, do not reply to prevent injection.

2 in general
·
1
$ SQL = "select * from user where user_name = $ username and password = $ password ";
$ Res = $ db_obj-> get_one ($ SQL );
If ($ res ){
// Login successful
}
·
·
2
$ SQL = "select * from user where user_name = $ username ";
$ Res = $ db_obj-> get_one ($ SQL );
If ($ res [password] = md5 ($ password )){
// Login successful
}
·
Any of the above two can be bypassed to seek security

Since the injection vulnerability already exists, not only logon can be bypassed, but your database is not secure. If you know the structure of your table, it is easy to insert an administrator account. So the key is to prevent injection, instead of what to do after injection.

Simplest
$ SQL = "select * from user where user_name = '". addslashes ($ username )."'";

Isn't the general writing method using orm to read and write databases?
Handwriting SQL is inherently insecure

Use PDO preprocessing statements

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.