Replay Protection#

Overview#

Replay protection is intentionally pluggable.

Available contract:

  • Infocyph\OTP\Contracts\ReplayStoreInterface

Included store:

  • Infocyph\OTP\Stores\InMemoryReplayStore

Example#

<?php
use Infocyph\OTP\Stores\InMemoryReplayStore;
use Infocyph\OTP\ValueObjects\VerificationWindow;

$store = new InMemoryReplayStore();

$result = $totp->verifyWithWindow(
    $otp,
    window: new VerificationWindow(past: 1, future: 1),
    replayStore: $store,
    binding: 'user-42',
);

Persistent implementations#

The in-memory replay store is mainly for tests and lightweight scenarios.

See Custom Persistent Stores for a database-oriented example implementing ReplayStoreInterface.