Table of Contents

Class PasswordResetTokenEntity

Namespace
FishMMO.Database.Npgsql.Entities
Assembly
FishMMO-DB.dll

A single outstanding "forgot my password" token.

public class PasswordResetTokenEntity
Inheritance
PasswordResetTokenEntity
Inherited Members

Remarks

Only the SHA-256 of the emailed token is stored, exactly as WebSessionEntity stores only the hash of a session identifier: a database read must not yield working reset tokens. A plain hash is correct here rather than a slow KDF because the token is 32 bytes of RandomNumberGenerator output and therefore not guessable — the hash exists to stop a leaked table being replayed, not to resist a dictionary.

Possession of a token proves control of the mailbox and nothing else. Redeeming one replaces the SRP credentials and must never touch totp_enabled, totp_secret, totp_verified_at or the recovery codes: if an emailed link could also clear the second factor, a compromised mailbox would be a complete account takeover and the second factor would protect nothing.

There is deliberately no foreign key to accounts, which is where this table differs from AuthTokenEntity and WebSessionEntity. Accounts are never deleted in this system, so the cascade those tables buy can never fire; and a row is only ever written after an account has already been read, so the constraint could never reject a row this code would otherwise create. The cost is that a row could outlive an account removed by hand — harmless, because redemption re-reads the account and refuses when it is missing or banned.

There is no xmin concurrency token either. Redemption is one conditional UPDATE (used_utc IS NULL AND expires_utc > now) whose WHERE clause is the concurrency control: two simultaneous redemptions of the same token cannot both affect a row.

Properties

AccountName

Account the token was issued for, matching accounts.name.

public string AccountName { get; set; }

Property Value

string

CreatedUtc

When the token was issued. Drives the per-account resend cooldown.

public DateTime CreatedUtc { get; set; }

Property Value

DateTime

ExpiresUtc

When the token stops being redeemable.

public DateTime ExpiresUtc { get; set; }

Property Value

DateTime

ID

Surrogate key.

public long ID { get; set; }

Property Value

long

RequestedIp

Client address that asked for the reset, for abuse investigation.

public string? RequestedIp { get; set; }

Property Value

string

TokenHash

Lowercase hex SHA-256 of the emailed token. The token itself is never stored.

public string TokenHash { get; set; }

Property Value

string

UsedUtc

When the token was redeemed, or null while it is still outstanding. Redeeming one token also stamps this on every other outstanding token for the account.

public DateTime? UsedUtc { get; set; }

Property Value

DateTime?