Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.3でトークン検証が通らなかったので修正 #57

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading