Skip to content

Commit 7b855b7

Browse files
committed
Updated Password class with a verify method.
Signed-off-by: Joshua Parker <[email protected]>
1 parent baba63a commit 7b855b7

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

Auth/Repository/PdoRepository.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
namespace Codefy\Framework\Auth\Repository;
66

7+
use Codefy\Framework\Support\Password;
78
use PDO;
89
use Qubus\Config\ConfigContainer;
910
use Qubus\Exception\Exception;
1011
use Qubus\Http\Session\SessionEntity;
1112

12-
use function password_verify;
1313
use function sprintf;
1414

1515
class PdoRepository implements AuthUserRepository
@@ -47,7 +47,7 @@ public function authenticate(string $credential, #[\SensitiveParameter] ?string
4747

4848
$passwordHash = (string) ($result->{$fields['password']} ?? '');
4949

50-
if (password_verify(password: $password ?? '', hash: $passwordHash)) {
50+
if (Password::verify(password: $password ?? '', hash: $passwordHash)) {
5151
$user = new class () implements SessionEntity {
5252
public ?string $token = null;
5353
public ?string $role = null;

Support/Password.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
namespace Codefy\Framework\Support;
66

77
use function defined;
8+
use function password_hash;
9+
use function password_verify;
810
use function Qubus\Security\Helpers\__observer;
911

1012
use const PASSWORD_ARGON2ID;
@@ -60,4 +62,16 @@ public static function hash(string $password): string
6062
{
6163
return password_hash(password: $password, algo: self::algorithm(), options: self::options());
6264
}
65+
66+
/**
67+
* Checks if the given hash matches the given options.
68+
*
69+
* @param string $password
70+
* @param string $hash
71+
* @return bool
72+
*/
73+
public static function verify(string $password, string $hash): bool
74+
{
75+
return password_verify($password, $hash);
76+
}
6377
}

0 commit comments

Comments
 (0)