I use the hash php hashing API and check my passwords on the site I create, however whenever I try to verify my password, it always returns false.
I have a custom class that sets a password before pasting into the database:
public function set__password($passwd) {
self::$password = password_hash($passwd, PASSWORD_BCRYPT, array('cost' => 12));
}
If the username and email address are unique, a new user line is added - when checking my database, I have what seems like the correct BCRYPT line for my password:
$2y$12$lTMEP0wevDEMX0bzStzoyOEzOTIAi3Hyhd3nYjGwzbI
To verify my password, I run the following script:
$username = $_POST['username'];
$password = $_POST['password'];
$DB = Database::getInstance();
$res = $DB->run__query('SELECT password FROM users WHERE username = "' . $username . '"');
$hash = $res[0]['password'];
if(password_verify($password, $hash)) {
echo 'success';
} else {
echo 'failed';
}
$hashrefers to the line above, however, when I then call password_verify($password, $hash)where $passwordis the plaintext password obtained from my input field, I always get false.
API , , !
,
.