PHP Web App How to write user logins when there is an injection to prevent the login from being bypassed by injection

Source: Internet
Author: User
PHP Web App How to write user logins when there is an injection to prevent the login from being bypassed by injection

If the condition is not changed, do not reply to prevent injection

2 of the general wording
·
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
}
·
The above 2 can be bypassed, to find a safe wording

Reply content:

PHP Web App How to write user logins when there is an injection to prevent the login from being bypassed by injection

If the condition is not changed, do not reply to prevent injection

2 of the general wording
·
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
}
·
The above 2 can be bypassed, to find a safe wording

Now that there is an injection vulnerability, not only can logins be bypassed, but even your databases are unsafe. If you know your table structure, it's easy to insert an administrator account. So the key is to prevent injection, not inject later what to do.

The simplest
$sql = "SELECT * from user where user_name= '". Addslashes ($username). "'";

Is the general notation not to use ORM to read and write databases?
Handwritten SQL, which is inherently unsafe

Using PDO preprocessing statements

  • Related Article

    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.