Skip to content
Snippets Groups Projects
Commit acbbef76 authored by Thijs Kinkhorst's avatar Thijs Kinkhorst
Browse files

Do not allow the password hash to be used for authentication.

parent 8ed53848
No related branches found
No related tags found
No related merge requests found
......@@ -356,6 +356,9 @@ class Crypto
*/
public static function pwValid(string $hash, string $password): bool
{
if (!is_null(password_get_info($password)['algo'])) {
throw new Error\Exception("Cannot use a hash value for authentication.");
}
if (password_verify($password, $hash)) {
return true;
}
......
......@@ -165,6 +165,18 @@ PHP;
$this->assertFalse($res);
}
/**
* Check that hash cannot be used to authenticate ith.
*/
public function testHashAsPwInvalid(): void
{
$pw = "password";
$hash = Crypto::pwHash($pw);
$this->expectException(Error\Exception::class);
$res = Crypto::pwValid($hash, $hash);
}
/**
*/
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment