So I know the basics of a SQL injection attack, with entries that are not sanitized. So
SELECT id FROM users WHERE username='$username' AND password='$password'
(Note that $password is hashed) would be defeated with $username=x'
or 1=1; --
A friend said that if you throw a \n character into your source code, then you can't comment the rest of the query out. So if you have
Select id
from users
where username='$username'
and password='$password'
in php, and then submit it to the query, then even if they tried to comment out the username, it would error because the and password='$password'
would still try and be executed.
I tried it, and he seems to be correct. So, my question is, while you should still sanitize your database inputs, does this prevent an attack like this, or is there a way to bypass it still?
I don't know if it matters, but I'm talking specifically about mysql here.