I was reading about the null-byte problem when using password_hash()
. This gave me two questions:
password_verify()
returns false when characters after \0
differ or are absent.str_replace(chr(0), '', $input)
. Should I use this when processing passwords? Should I use something else too?You can test this with
$hash = password_hash("\x00 abc", PASSWORD_DEFAULT);
var_dump(password_verify("\x00 foo", $hash)); // true ???
But when submitting a password from ie a form you receive the string '\x00 password' which will not interpolate like "\x00 password" would (single vs double quotes).
$hash = password_hash("\x00 abc", PASSWORD_DEFAULT);
var_dump(password_verify('\x00 foo', $hash)); // false!