I have found a PHP preg match for A-Z,a-z,0-9, _,-, and one space. I am using it for username validation on my website. I will redirect if the preg_match is "not secure enough". I think the only character I need to worry about is the _ (underscore) from what I am reading up on. Does anyone know any SQL injection code I can run and test if this case is vulnerable? Or is this code sufficient for what I'm trying to achieve. PS - I will also be using prepared statements since this user input will be going to my database...
// escapes special characters
$username = mysqli_real_escape_string($connection, $username);
// checks to see if characters other than A-Z, a-z, 0-9, " "(white space), -(hyphen), and _ (underscore)...
if (preg_match('/^[a-zA-Z0-9\040\_\-]+$/i', $username))
{
echo 'secure';
}
else
{
echo 'not secure';
}