From a27f840eda49f12260ae313cc13e75bcebbee74a Mon Sep 17 00:00:00 2001 From: hiro-gj <49264814+hiro-gj@users.noreply.github.com> Date: Fri, 30 Oct 2026 08:45:27 +0900 Subject: [PATCH] fix(Security\Hasher): Guard PASSWORD_ARGON2 constants with defined() check Guard constant references with defined() checks so that systems without Argon2 support can safely fall back to bcrypt without fatal errors. Follow-up to #64733 Fixes #65780 Signed-off-by: hiro-gj <49264814+hiro-gj@users.noreply.github.com> --- lib/private/Security/Hasher.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/private/Security/Hasher.php b/lib/private/Security/Hasher.php index 99b57029adbfc..c16178ef4d2fa 100644 --- a/lib/private/Security/Hasher.php +++ b/lib/private/Security/Hasher.php @@ -74,13 +74,15 @@ public function __construct( public function hash(string $message): string { $alg = $this->getPrefferedAlgorithm(); - $version = match ($alg) { - PASSWORD_ARGON2ID => 3, - PASSWORD_ARGON2I => 2, - PASSWORD_BCRYPT => 1, - }; + if (\defined('PASSWORD_ARGON2ID') && $alg === PASSWORD_ARGON2ID) { + return 3 . '|' . password_hash($message, PASSWORD_ARGON2ID, $this->options); + } + + if (\defined('PASSWORD_ARGON2I') && $alg === PASSWORD_ARGON2I) { + return 2 . '|' . password_hash($message, PASSWORD_ARGON2I, $this->options); + } - return $version . '|' . password_hash($message, $alg, $this->options); + return 1 . '|' . password_hash($message, PASSWORD_BCRYPT, $this->options); } /**