Table of Contents

Class PasswordResetService

Namespace
FishMMO.ControlPanel.Services
Assembly
FishMMO-ControlPanel.dll

"Forgot password" recovery: the path for an account holder who cannot sign in at all.

public sealed class PasswordResetService
Inheritance
PasswordResetService
Inherited Members

Remarks

The server never sees a password here either. The browser generates a new SRP salt and derives a new verifier from the username and the password the user typed, and sends only those; ChangePasswordAsync(string, string, string, CancellationToken) — the one credential write in the panel — persists them. There is deliberately no second path that writes a verifier.

A reset does not satisfy or weaken two-factor. Nothing here touches totp_enabled, totp_secret, totp_verified_at or the recovery codes, and nothing may be added that does. After a reset the account holder still has to pass TOTP or burn a recovery code at sign-in. That is the whole point of the split: the eight recovery codes are the answer to a lost authenticator and email is the answer to a lost password. If an emailed link could also clear the second factor, compromising a mailbox would be a complete account takeover and the second factor would protect nothing.

The token is a secret. At least 32 bytes of RandomNumberGenerator output go to the mailbox; only its SHA-256 is stored, so a database read yields no working tokens. A plain hash rather than a slow KDF is right because the token is full-entropy random and not guessable — the hash exists to stop a leaked table being replayed, not to resist a dictionary.

No account enumeration: RequestAsync(string, string, CancellationToken) reports nothing about whether the address is registered, whether the account is banned, or whether the resend cooldown suppressed the mail. The caller answers the same way regardless.

Constructors

PasswordResetService(IAccountService, IPasswordResetTokenService, IEmailQueueService, IWebSessionService, SelfServiceService, PanelRegistrationOptions, IWebHostEnvironment, ILogger<PasswordResetService>)

public PasswordResetService(IAccountService accounts, IPasswordResetTokenService resetTokens, IEmailQueueService emailQueue, IWebSessionService webSessions, SelfServiceService selfService, PanelRegistrationOptions options, IWebHostEnvironment environment, ILogger<PasswordResetService> log)

Parameters

accounts IAccountService
resetTokens IPasswordResetTokenService
emailQueue IEmailQueueService
webSessions IWebSessionService
selfService SelfServiceService
options PanelRegistrationOptions
environment IWebHostEnvironment
log ILogger<PasswordResetService>

Fields

InvalidCodeError

The one answer for an unknown, malformed, expired or already-used code.

public const string InvalidCodeError = "That reset code is not valid or has expired."

Field Value

string

Remarks

Distinguishing them would tell an attacker which of their guesses was structurally right, so every failure in this file uses this exact string.

Methods

CompleteAsync(string, string, string, CancellationToken)

Spends a reset token and installs the browser-derived credentials.

public Task<PasswordResetService.Outcome> CompleteAsync(string code, string salt, string verifier, CancellationToken cancellationToken = default)

Parameters

code string
salt string
verifier string
cancellationToken CancellationToken

Returns

Task<PasswordResetService.Outcome>

Remarks

Order matters and is deliberate. The token is spent first, by one conditional UPDATE in the database, so a double submission cannot write twice; a credential write that then fails costs the account holder a second email, which is the cheap direction to fail in. Afterwards every panel session and every game token for the account is revoked and any other outstanding reset token is invalidated.

The revocations are the point rather than housekeeping. A reset is what somebody does when they believe their account is compromised, so a session left alive would defeat it, and a reset token requested earlier by an attacker would still be live in their hands the moment the victim finished resetting.

The game tokens are revoked inside ChangePasswordAsync(string, string, string, CancellationToken) rather than here, which is the one place in this sequence that differs from the obvious reading of "credentials, sessions, tokens": reusing the panel's single credential write is worth more than the interleaving, and all three are attempted before this method returns. A revocation that fails does not undo the reset; it is logged and comes back as SignedOutEverywhere false, so the reply can say so.

LookupUsernameAsync(string, CancellationToken)

Returns the account name a valid, unexpired, unused token belongs to, or null.

public Task<string> LookupUsernameAsync(string code, CancellationToken cancellationToken = default)

Parameters

code string
cancellationToken CancellationToken

Returns

Task<string>

Remarks

The browser needs the username before it can derive a verifier, because the username is an input to the SRP key derivation. Handing it to somebody holding the token gives away nothing: the token went to that account's mailbox, and the mail names the account already. This is a read — it does not spend the token, which only CompleteAsync(string, string, string, CancellationToken) does.

RequestAsync(string, string, CancellationToken)

Issues a reset token for the account at an email address and queues the mail.

public Task<PasswordResetService.RequestOutcome> RequestAsync(string email, string requestedIp, CancellationToken cancellationToken = default)

Parameters

email string
requestedIp string
cancellationToken CancellationToken

Returns

Task<PasswordResetService.RequestOutcome>

Remarks

Every refusal returns the same empty outcome, and the caller answers identically in all of them: an unknown address, a malformed one, a banned account, a cooldown still running, or a database that is down. An endpoint that answered differently for a registered address would be an account enumeration oracle, which is exactly what a password reset form is probed for.

Banned accounts are never mailed. A reset cannot help them — the access level, not the password, is what refuses the login — and sending would make the endpoint an abuse vector against whoever owns the address. FetchForLoginAsync already refuses a banned account, and refuses it with the same failure as a missing one.