From 215efadaa3fd79b37ab50fbfb0a1334c0398590d Mon Sep 17 00:00:00 2001 From: Chihiro Adachi <8196725+chihiro-adachi@users.noreply.github.com> Date: Tue, 26 Mar 2024 16:48:54 +0900 Subject: [PATCH] =?UTF-8?q?4.3=E3=81=A7=E3=83=88=E3=83=BC=E3=82=AF?= =?UTF-8?q?=E3=83=B3=E6=A4=9C=E8=A8=BC=E3=81=8C=E9=80=9A=E3=82=89=E3=81=AA?= =?UTF-8?q?=E3=81=8B=E3=81=A3=E3=81=9F=E3=81=AE=E3=81=A7=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CustomerPersonalValidationController.php | 17 ++++------------- Service/CustomerTwoFactorAuthService.php | 10 ++++++++-- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/Controller/CustomerPersonalValidationController.php b/Controller/CustomerPersonalValidationController.php index f41ba4e..ec43123 100644 --- a/Controller/CustomerPersonalValidationController.php +++ b/Controller/CustomerPersonalValidationController.php @@ -237,20 +237,11 @@ private function checkDeviceToken($Customer, $token): bool { $now = new \DateTime(); - // フォームからのハッシュしたワンタイムパスワードとDBに保存しているワンタイムパスワードのハッシュは一致しているかどうか - if (version_compare(Constant::VERSION, '4.3', '>=') && - !$this->customerTwoFactorAuthService->veriyOneTimeToken($Customer->getDeviceAuthOneTimeToken(), $token) || - $Customer->getDeviceAuthOneTimeTokenExpire() < $now) { - return false; - } else { - if ( - $Customer->getDeviceAuthOneTimeToken() !== $this->customerTwoFactorAuthService->hashOneTimeToken($token) || - $Customer->getDeviceAuthOneTimeTokenExpire() < $now) { - return false; - } - } + $hashedToken = $Customer->getDeviceAuthOneTimeToken(); + $expire = $Customer->getDeviceAuthOneTimeTokenExpire(); - return true; + // トークン検証 + return $this->customerTwoFactorAuthService->verifyOneTimeToken($hashedToken, $token) && $expire > $now; } /** diff --git a/Service/CustomerTwoFactorAuthService.php b/Service/CustomerTwoFactorAuthService.php index add63e0..99d78af 100644 --- a/Service/CustomerTwoFactorAuthService.php +++ b/Service/CustomerTwoFactorAuthService.php @@ -428,9 +428,15 @@ public function hashOneTimeToken(string $token): string return $this->hashFactory->getPasswordHasher(Customer::class)->hash($token); } - public function veriyOneTimeToken(string $hashedToken, string $token): bool + public function verifyOneTimeToken(string $hashedToken, string $token): bool { - return $this->hashFactory->getPasswordHasher(Customer::class)->verify($hashedToken, $token); + if ($this->hashFactory->getPasswordHasher(Customer::class)->verify($hashedToken, $token)) { + return true; + } elseif ($hashedToken === $this->hashOneTimeToken($token)) { + return true; + } else { + return false; + } } /***