From 3625622670f135e30ece750537fc8bf64882c05a Mon Sep 17 00:00:00 2001 From: Marco Date: Sat, 17 May 2025 18:19:07 +0200 Subject: [PATCH] Extract usages of hashing for passwords to new class 'PasswordHash' --- src/Auth.php | 6 +++--- src/PasswordHash.php | 46 ++++++++++++++++++++++++++++++++++++++++++++ src/UserManager.php | 4 ++-- 3 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 src/PasswordHash.php diff --git a/src/Auth.php b/src/Auth.php index 6ec8dfd..dc230ec 100644 --- a/src/Auth.php +++ b/src/Auth.php @@ -366,7 +366,7 @@ final class Auth extends UserManager { } if (!empty($expectedHash)) { - $validated = \password_verify($password, $expectedHash); + $validated = PasswordHash::verify($password, $expectedHash); if (!$validated) { $this->throttle([ 'reconfirmPassword', $this->getIpAddress() ], 3, (60 * 60), 4, false); @@ -1229,9 +1229,9 @@ final class Auth extends UserManager { $password = self::validatePassword($password); - if (\password_verify($password, $userData['password'])) { + if (PasswordHash::verify($password, $userData['password'])) { // if the password needs to be re-hashed to keep up with improving password cracking techniques - if (\password_needs_rehash($userData['password'], \PASSWORD_DEFAULT)) { + if (PasswordHash::needsRehash($userData['password'])) { // create a new hash from the password and update it in the database $this->updatePasswordInternal($userData['id'], $password); } diff --git a/src/PasswordHash.php b/src/PasswordHash.php new file mode 100644 index 0000000..1eccd09 --- /dev/null +++ b/src/PasswordHash.php @@ -0,0 +1,46 @@ +db->update(