note 115120 deleted from function.password-verify by salathe
| From: | salathe@php.net | Date: | Mon, 21 Sep 2020 14:44:35 +0000 |
| Subject: | note 115120 deleted from function.password-verify by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-215294@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
If you get incorrect false responses from password_verify when manually including the hash variable
(eg. for testing) and you know it should be correct, make sure you are enclosing the hash variable
in single quotes (') and not double quotes (").
PHP parses anything that starts with a $ inside double quotes as a variable:
<?php
// this will result in 'Invalid Password' as the hash is parsed into 3 variables of
// $2y, $07 and $BCryptRequires22Chrcte/VlQH0piJtjXl.0t1XkA8pw9dMXTpOq
// due to it being enclosed inside double quotes
$hash = "$2y$07$BCryptRequires22Chrcte/VlQH0piJtjXl.0t1XkA8pw9dMXTpOq";
// this will result in 'Password is valid' as variables are not parsed inside single
quotes
$hash = '$2y$07$BCryptRequires22Chrcte/VlQH0piJtjXl.0t1XkA8pw9dMXTpOq';
if (password_verify('rasmuslerdorf', $hash)) {
echo 'Password is valid!';
} else {
echo 'Invalid password.';
}
?>