I have a function that validates for alphanumeric characters when someone sets or changes their password. While this is good I would like to allow for non-alphanumeric characters to be used as well to create stronger passwords.
Here is the function I have so far:
// checks if a character is between A-Z or 0-9
function is_alphanum($input) {
return (("a" <= $input && $input <="z") || ("A" <= $input && $input <="Z") || ("0" <= $input && $input <="9"))?true:false;
}
// checks if a string is between A-Z or 0-9
function is_alphanum_str($input) {
$alphanum_str = false;
for ($i=0;$i<strlen($input);$i++) {
if (is_alphanum(substr($input,$i,1)) == false) $alphanum_str = true;
}
return $alphanum_str;
}
How can I incorporate non-alphanumeric characters? In other words I would like to be able to specify that a password must have at least 1 non-alphanumeric character.