Reputation: 664
On my app's registration page, there is a field for the user's name. I would like to prevent SQL injection attacks while allowing complex names like Aldéric D'Aurve-Sanct
, which contain single quotes used as apostrophes.
If I whitelist the name using a regex string like this one, can I then use double quotes (which are not allowed in the name) to fully escape the string? In other words, is it safe to use a string containing single quotes, but not other control characters, when surrounded by double quotes? Are there any vulnerabilities which such simple solution might introduce?
Note: I don't want to use prepared statements in this instance.
Upvotes: 0
Views: 100
Reputation: 4826
If you really can't use prepared statements, never escape yourself, there is functions to do it if you ever need it.
For example, if you use php PDO, use PDO::quote : https://secure.php.net/manual/en/pdo.quote.php
But, use prepared statements if possible :
Upvotes: 1