Skip to content

Commit

Permalink
Merge pull request #57 from chihiro-adachi/fix-4.3
Browse files Browse the repository at this point in the history
4.3でトークン検証が通らなかったので修正
  • Loading branch information
chihiro-adachi authored Apr 8, 2024
2 parents 58956a6 + 215efad commit 995e370
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
17 changes: 4 additions & 13 deletions Controller/CustomerPersonalValidationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
10 changes: 8 additions & 2 deletions Service/CustomerTwoFactorAuthService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

/***
Expand Down

0 comments on commit 995e370

Please sign in to comment.