Interface ITwoFactorRecoveryCodeService
- Namespace
- FishMMO.Database.Npgsql.Services.Interfaces
- Assembly
- FishMMO-DB.dll
Service interface for managing two-factor recovery codes. Recovery codes are one-time-use fallbacks when TOTP is unavailable. The server hashes codes before passing them to this layer.
public interface ITwoFactorRecoveryCodeService
Methods
ConsumeCodeAsync(string, string, CancellationToken)
Atomically marks a single unused recovery code as consumed by setting used_at. Returns success only if the code was found and was previously unused.
Task<DatabaseResult> ConsumeCodeAsync(string accountName, string codeHash, CancellationToken cancellationToken = default)
Parameters
accountNamestringThe account that owns the code.
codeHashstringThe hashed code to consume.
cancellationTokenCancellationTokenCancellation token.
Returns
DeleteAllForAccountAsync(string, CancellationToken)
Deletes all recovery codes (used and unused) for an account. Called when TOTP is disabled or recovery codes are regenerated.
Task<DatabaseResult> DeleteAllForAccountAsync(string accountName, CancellationToken cancellationToken = default)
Parameters
accountNamestringcancellationTokenCancellationToken
Returns
FetchUnusedByAccountAsync(string, CancellationToken)
Fetches all unused recovery codes for an account.
Task<DatabaseResult<List<TwoFactorRecoveryCodeData>>> FetchUnusedByAccountAsync(string accountName, CancellationToken cancellationToken = default)
Parameters
accountNamestringcancellationTokenCancellationToken
Returns
PersistManyAsync(string, IReadOnlyList<string>, CancellationToken)
Batch-inserts a set of pre-hashed recovery codes for an account. Called during TOTP enrollment or recovery code regeneration.
Task<DatabaseResult> PersistManyAsync(string accountName, IReadOnlyList<string> codeHashes, CancellationToken cancellationToken = default)
Parameters
accountNamestringThe account to associate codes with.
codeHashesIReadOnlyList<string>Pre-hashed recovery codes to store.
cancellationTokenCancellationTokenCancellation token.