Table of Contents

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

accountName string

The account that owns the code.

codeHash string

The hashed code to consume.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<DatabaseResult>

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

accountName string
cancellationToken CancellationToken

Returns

Task<DatabaseResult>

FetchUnusedByAccountAsync(string, CancellationToken)

Fetches all unused recovery codes for an account.

Task<DatabaseResult<List<TwoFactorRecoveryCodeData>>> FetchUnusedByAccountAsync(string accountName, CancellationToken cancellationToken = default)

Parameters

accountName string
cancellationToken CancellationToken

Returns

Task<DatabaseResult<List<TwoFactorRecoveryCodeData>>>

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

accountName string

The account to associate codes with.

codeHashes IReadOnlyList<string>

Pre-hashed recovery codes to store.

cancellationToken CancellationToken

Cancellation token.

Returns

Task<DatabaseResult>