r/PHPhelp • u/adinbied • Oct 24 '16
Solved Am I vulnerable?
Hi there,
I just finished preparing my registration page with PDO, and wanted to make sure that I am not vulnerable to SQL Injection. If someone could look over what I have here: http://pastie.org/10949079 it would be much appreciated. I think (hopefully) that I am good, but would like a second opinion.
Thanks!
2
Oct 25 '16
A combination of prepared statements (which you've used) and validating input can go a long way with helping.
Eg. Does the email match an email pattern, limiting first and last name string length etc.
Other things to consider:
Don't allow a user to submit lengthy strings.
Limit char limits in column tables to assumed lengths.
Ask yourself if there should be strict types. Eg. Age should be set as an integer in tables and validated as being numeric.
1
6
u/dyloot Oct 24 '16
You do 3 queries and each of the 3 queries are done using prepared statements. I believe you are not vulnerable to SQL injection.
5
3
u/halfercode Oct 25 '16
Thanks for the PM, and thanks for posting this. Looks good to me.
I would modify the hashing algorithm to
PASSWORD_DEFAULT, so that if a new PHP release comes with a better default algorithm it will switch automatically.I'd improve the indentation a bit too, just for readability - did you know PHP works well with multiline statements? You can wrap however you feel it is readable: