Interface IPasswordResetTokenService
- Namespace
- FishMMO.Database.Npgsql.Services.Interfaces
- Assembly
- FishMMO-DB.dll
Outstanding "forgot my password" tokens.
public interface IPasswordResetTokenService
Remarks
Every method takes the SHA-256 hex of the emailed token, never the token itself — hashing is the caller's job, so the redeemable value never reaches this layer at all. This mirrors IWebSessionService, which takes session hashes for the same reason.
Methods
CleanupExpiredAsync(DateTime, CancellationToken)
Deletes tokens that expired before the cutoff. Returns how many rows went.
Task<DatabaseResult<int>> CleanupExpiredAsync(DateTime cutoffUtc, CancellationToken cancellationToken = default)
Parameters
cutoffUtcDateTimecancellationTokenCancellationToken
Returns
FetchByHashAsync(string, CancellationToken)
Fetches a token row by hash, whatever its state.
Task<DatabaseResult<PasswordResetTokenData>> FetchByHashAsync(string tokenHash, CancellationToken cancellationToken = default)
Parameters
tokenHashstringcancellationTokenCancellationToken
Returns
Remarks
Returns the row for an expired or already-used token too; the caller applies those checks. Read-only — use RedeemAsync(string, CancellationToken) to actually spend a token, because only that path marks it used atomically.
HasRecentForAccountAsync(string, DateTime, CancellationToken)
Whether the account has been issued a token since sinceUtc.
Task<DatabaseResult<bool>> HasRecentForAccountAsync(string accountName, DateTime sinceUtc, CancellationToken cancellationToken = default)
Parameters
accountNamestringsinceUtcDateTimecancellationTokenCancellationToken
Returns
Remarks
The resend cooldown. It exists so the request endpoint cannot be used to flood somebody's inbox, and it must never change what the endpoint answers.
InvalidateAllForAccountAsync(string, string?, CancellationToken)
Marks every outstanding token for an account used, optionally sparing one.
Task<DatabaseResult<int>> InvalidateAllForAccountAsync(string accountName, string? exceptTokenHash, CancellationToken cancellationToken = default)
Parameters
accountNamestringAccount whose tokens go.
exceptTokenHashstringA hash to leave alone, or null to invalidate all.
cancellationTokenCancellationTokenCancellation token.
Returns
- Task<DatabaseResult<int>>
How many rows were invalidated.
Remarks
Called after a successful redemption. Without it, an attacker who requested a reset earlier would still hold a live token after the account holder had reset their password — which is exactly the case a reset exists to close.
IssueAsync(string, string, DateTime, string?, CancellationToken)
Records a newly issued reset token.
Task<DatabaseResult<PasswordResetTokenData>> IssueAsync(string tokenHash, string accountName, DateTime expiresUtc, string? requestedIp, CancellationToken cancellationToken = default)
Parameters
tokenHashstringSHA-256 hex of the emailed token.
accountNamestringAccount the token resets.
expiresUtcDateTimeWhen the token stops being redeemable.
requestedIpstringClient address that asked, or null.
cancellationTokenCancellationTokenCancellation token.
Returns
RedeemAsync(string, CancellationToken)
Spends a token: marks it used and returns the account it belongs to.
Task<DatabaseResult<string>> RedeemAsync(string tokenHash, CancellationToken cancellationToken = default)
Parameters
tokenHashstringcancellationTokenCancellationToken
Returns
- Task<DatabaseResult<string>>
The account name on success, DB_NOT_FOUND when the token is not spendable.
Remarks
One conditional UPDATE — used_utc IS NULL AND expires_utc > now — so the
check and the mark cannot be separated by a racing second redemption. A token that is
unknown, expired or already used all fail the same way, with DB_NOT_FOUND; the caller
must not distinguish them to the browser either.