Class TwoFactorService
- Namespace
- FishMMO.ControlPanel.Services
- Assembly
- FishMMO-ControlPanel.dll
Verifies TOTP codes and recovery codes, mirroring
ServerAuthenticator.VerifyTotpCodeCoreAsync exactly.
public sealed class TwoFactorService
- Inheritance
-
TwoFactorService
- Inherited Members
Remarks
Identical rules to the game path, deliberately: the recovery-code shape test, the replay window persistence, the first-verification stamp, and single-use consumption. A code that works in the client works here, and one consumed here is gone there too.
Constructors
TwoFactorService(IAccountService, ITwoFactorRecoveryCodeService, ITwoFactorResetRequestService, SecurityNoticeService, AuthLockoutOptions, TotpKeyProvider, ILogger<TwoFactorService>)
public TwoFactorService(IAccountService accounts, ITwoFactorRecoveryCodeService recoveryCodes, ITwoFactorResetRequestService resetRequests, SecurityNoticeService notices, AuthLockoutOptions lockout, TotpKeyProvider totpKeys, ILogger<TwoFactorService> log)
Parameters
accountsIAccountServicerecoveryCodesITwoFactorRecoveryCodeServiceresetRequestsITwoFactorResetRequestServicenoticesSecurityNoticeServicelockoutAuthLockoutOptionstotpKeysTotpKeyProviderlogILogger<TwoFactorService>
Methods
VerifyAsync(string, string, CancellationToken)
Verifies a TOTP code or a recovery code for an account.
public Task<bool> VerifyAsync(string username, string code, CancellationToken cancellationToken = default)
Parameters
usernamestringcodestringcancellationTokenCancellationToken
Returns
VerifyForSignInAsync(string, string, bool, CancellationToken)
A two-factor check at sign-in or step-up: lockout, verification, failure count, and the cancellation of a pending self-service reset.
public Task<TwoFactorService.Check> VerifyForSignInAsync(string username, string code, bool authenticatorOnly, CancellationToken cancellationToken = default)
Parameters
usernamestringcodestringauthenticatorOnlyboolRefuse recovery codes: the reset confirmation must prove the NEW authenticator.
cancellationTokenCancellationToken
Returns
Remarks
The session asking has already proven the password, so unlike the password step a lock is stated plainly, with its end: there is nobody left to hide the account's existence from.
A good code cancels a pending two-factor reset, and the holder is told. Passing the real factor proves the owner still has it, which is precisely the case the reset's waiting period exists to catch.
VerifyPendingAsync(string, string, CancellationToken)
Checks a code against the account's STAGED authenticator — the one a re-enrolment has not confirmed yet — without touching anything sign-in reads.
public Task<TwoFactorService.PendingCheck> VerifyPendingAsync(string username, string code, CancellationToken cancellationToken = default)
Parameters
usernamestringcodestringcancellationTokenCancellationToken
Returns
Remarks
An authenticator code only: confirming a new authenticator with a recovery code would prove
nothing about the new one. Nothing is persisted here; the window a valid code used is
returned for SelfServiceService.ConfirmTwoFactorAsync, which records it as it
promotes the secret, so the confirming code cannot be replayed at sign-in.