Table of Contents

Class TwoFactorResetFlow

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

The self-service two-factor reset, for an account holder who has lost the authenticator AND every recovery code.

public sealed class TwoFactorResetFlow
Inheritance
TwoFactorResetFlow
Inherited Members

Remarks

The rules this exists to keep.

  • Only a session that has already proven the password may ask, and asking starts a waiting period (DelayDays). The holder is emailed immediately; any successful sign-in with the real factor during the wait cancels it (VerifyForSignInAsync(string, string, bool, CancellationToken)). A stolen password alone therefore buys a week's notice to the real owner, not an account.
  • Asking again returns the same request. The clock is never restarted (that would let an attacker keep the owner's cancellation window open forever) and never shortened.
  • Completing a reset never satisfies two-factor. It replaces the factor and hands the new one over; the session is promoted only after a code from the NEW authenticator is typed.
  • The account is never left with two-factor cleared. The new secret overwrites the old one while totp_enabled stays on, and the recovery codes are replaced in the same step, so the game login demands the new authenticator from the moment the reset completes. Clearing first and enrolling second would leave a window — or, on a failed write, an account — with the password as the only thing in front of it.
  • Completion is one transaction: the request is spent together with the new factor, or not at all. A failure part-way leaves the request pending and the old factor in place.
  • A password reset never satisfies two-factor and a recovery code never resets a password: nothing here touches the SRP credentials, and PasswordResetService touches nothing here.

Constructors

TwoFactorResetFlow(ITwoFactorResetRequestService, IAuthTokenService, IWebSessionService, SelfServiceService, SecurityNoticeService, IUnitOfWorkService, TotpKeyProvider, TwoFactorResetOptions, ILogger<TwoFactorResetFlow>)

public TwoFactorResetFlow(ITwoFactorResetRequestService requests, IAuthTokenService authTokens, IWebSessionService webSessions, SelfServiceService selfService, SecurityNoticeService notices, IUnitOfWorkService unitOfWork, TotpKeyProvider totpKeys, TwoFactorResetOptions resetOptions, ILogger<TwoFactorResetFlow> log)

Parameters

requests ITwoFactorResetRequestService
authTokens IAuthTokenService
webSessions IWebSessionService
selfService SelfServiceService
notices SecurityNoticeService
unitOfWork IUnitOfWorkService
totpKeys TotpKeyProvider
resetOptions TwoFactorResetOptions
log ILogger<TwoFactorResetFlow>

Methods

CompleteAsync(string, CancellationToken)

Uses an effective request: replaces the authenticator and recovery codes, signs everything else out, and returns the new factor for the handover screen. Does NOT satisfy two-factor.

public Task<TwoFactorResetFlow.Completion> CompleteAsync(string username, CancellationToken cancellationToken = default)

Parameters

username string
cancellationToken CancellationToken

Returns

Task<TwoFactorResetFlow.Completion>

Remarks

Every panel session for the account is revoked, the caller's included; the controller issues the caller a fresh PENDING session, which is what keeps "completing is not passing" true even at the level of the session row.

Describe(TwoFactorResetRequestData, TwoFactorResetOptions)

The request as the browser sees it. Never the IP of whoever asked.

public static object Describe(TwoFactorResetRequestData request, TwoFactorResetOptions options)

Parameters

request TwoFactorResetRequestData
options TwoFactorResetOptions

Returns

object

PendingAsync(string, CancellationToken)

The pending request: Read is false when the database could not be asked, which is not the same answer as a successful read that found no request.

public Task<(bool Read, TwoFactorResetRequestData Request)> PendingAsync(string username, CancellationToken cancellationToken = default)

Parameters

username string
cancellationToken CancellationToken

Returns

Task<(bool Read, TwoFactorResetRequestData Request)>

Remarks

This used to return a bare null for both, and every caller took a failed read for "there is no reset" — telling the player their request had gone, and letting completion report NoRequest over a database outage.

RequestAsync(string, string, CancellationToken)

Opens a request, or returns the one already pending unchanged. Emails the holder only when a new request was opened.

public Task<(TwoFactorResetRequestData Request, string Error)> RequestAsync(string username, string requestedIp, CancellationToken cancellationToken = default)

Parameters

username string
requestedIp string
cancellationToken CancellationToken

Returns

Task<(TwoFactorResetRequestData Request, string Error)>