Jul 2, 2019 09:07 AM
(This post was last modified: Jul 2, 2019 09:36 AM by Truth3356.
Edit Reason: Adding code tags
)
I need help fixing "unexpected '='" , i'm going insane figuring it out, i know it has to do with characters in a variable name, but i still cant figure out what the issue is here :
PHP Code
<?php $loginsql = "SELECT * FROM logins WHERE username" = "'$_POST;['userBox']. ";' && password = "' . sha1($_POST['passBox']) . "'";
Jul 2, 2019 09:18 AM
(This post was last modified: Jul 2, 2019 09:18 AM by l0lwtf.)
Try the following:
WARNING: this code is insecure. It is vulnerable to SQL injection.
DO NOT DEAL WITH THIS MEMBER
Please use code tags so we can make better sense of the code op.
(Jul 2, 2019 09:18 AM)l0lwtf Wrote: Try the following:
WARNING: this code is insecure. It is vulnerable to SQL injection.
Thank you sir.
(Jul 2, 2019 09:36 AM)Truth3356 Wrote: Thank you sir.
Be aware of what the member posted. The code you supplied is vulnerable to SQL injection and would allow your database to be dumped, deleted, etc.
(Jul 2, 2019 12:53 PM)Xerotic Wrote: Be aware of what the member posted. The code you supplied is vulnerable to SQL injection and would allow your database to be dumped, deleted, etc.
Totally, i did take notice of it, i don't have plans of making this public anytime soon, so i will get it fixed prior to doing that.
(Jul 2, 2019 01:10 PM)Truth3356 Wrote: Totally, i did take notice of it, i don't have plans of making this public anytime soon, so i will get it fixed prior to doing that.
I highly suggest to consider PDO (prepared statements). https://www.php.net/manual/en/book.pdo.php
They are the best standard right now and will help keep your code safer.
The login looks really sloppy, prone to injections. You have no sort of filter for userBox.
As Xerotic said, look into prepared statements. MySQLI even has procedural statements if OOP is a bit much.
$userBox = $_POST['userBox'];
$password = sha1($_POST['passBox']);
$loginsql = "SELECT * FROM `logins` WHERE `username` = '{$userBox}' AND `password` = '{$password}'"
^
Above will work and looks more readable
Jul 4, 2019 12:19 AM
(This post was last modified: Jul 4, 2019 12:43 AM by Kallu609.)
(Jul 2, 2019 12:53 PM)Xerotic Wrote: ...
Holy shit Xerotic is still in the game 😁
I remember seeing you active in the Python section years ago. You've taught me a few things too, thanks for that!
(Jul 2, 2019 03:51 PM)Pinhead Larry Wrote: The login looks really sloppy, prone to injections. You have no sort of filter for userBox.
As Xerotic said, look into prepared statements. MySQLI even has procedural statements if OOP is a bit much.
$userBox = $_POST['userBox'];
$password = sha1($_POST['passBox']);
$loginsql = "SELECT * FROM `logins` WHERE `username` = '{$userBox}' AND `password` = '{$password}'"
^
Above will work and looks more readable
No that's not how MySQLi, PDO or preventing SQLi attacks work. That's just string formatting (no escaping of characters, very BAD). To answer OP's question, this is what you have to do with PDO:
You can also use "?"s as placeholders, more info here: PHP: Prepared statements and stored procedures - Manual
(Jul 4, 2019 12:19 AM)Kallu609 Wrote: Holy shit Xerotic is still in the game 😁
I remember seeing you active in the Python section years ago. You've taught me a few things too, thanks for that!
No that's not how MySQLi, PDO or preventing SQLi attacks work. That's just string formatting (no escaping of characters, very BAD). To answer OP's question, this is what you have to do with PDO:
You can also use "?"s as placeholders, more info here: PHP: Prepared statements and stored procedures - Manual
Ive been fixing it with parameterized statements.
|