Table of Contents

Class AccountRegistrationService

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

Creates accounts from the browser, performing exactly the same steps, in the same order, as the LoginServer's AccountCreationSystem.

public sealed class AccountRegistrationService
Inheritance
AccountRegistrationService
Inherited Members

Remarks

The two paths must not drift: an account created on the web and an account created in the game client have to be indistinguishable afterwards, or a player who registered on one and signed in on the other would find their 2FA missing, their verification never sent, or their salt and verifier shaped differently.

The sequence mirrored from AccountCreationSystem.ProcessAccountCreationAsync, with the panel's additions marked:

  1. Validate the username against IsAllowedUsername(string).
  2. Bound the salt and verifier lengths (256 / 1024).
  3. (panel) Validate the optional profile with TryValidate(AccountProfileData, out AccountProfileData, out string).
  4. (panel) With the beta gate on, or a code given, check the code is redeemable — BEFORE the account exists.
  5. Persist the account with IAccountService.PersistAsync.
  6. (panel) Persist the profile and chosen channels, then redeem the beta code.
  7. Auto-verify when the development policy says so or the server verifies nothing; otherwise send a code on every channel Effective(AccountVerificationChannels, AccountVerificationChannels, AccountVerificationChannels) names, or verify without one when it names none.
  8. Only when the player opted in to two-factor: generate a TOTP secret, encrypt it under the deployment master KEK, persist it, then enable TOTP.
  9. With it, generate recovery codes, hash them, persist them. (panel) The secret, the enable and the codes are one transaction — see EnrolAsync(string, bool, CancellationToken).
  10. Return the otpauth URI and the plaintext recovery codes once (none without the opt-in).

Everything after the account row exists is best effort, as it is in game: a follow-on step that fails is logged, and the account is kept rather than a half-made registration being reported as a failure the player then retries into "that name is taken".

Constructors

AccountRegistrationService(IAccountService, IEmailQueueService, ISmsQueueService, IBetaCodeService, ISupportTicketService, PanelRegistrationOptions, VerificationOptions, BetaOptions, VerificationResendThrottle, SelfServiceService, ILogger<AccountRegistrationService>)

public AccountRegistrationService(IAccountService accounts, IEmailQueueService emailQueue, ISmsQueueService smsQueue, IBetaCodeService betaCodes, ISupportTicketService supportTickets, PanelRegistrationOptions options, VerificationOptions verification, BetaOptions beta, VerificationResendThrottle throttle, SelfServiceService selfService, ILogger<AccountRegistrationService> log)

Parameters

accounts IAccountService
emailQueue IEmailQueueService
smsQueue ISmsQueueService
betaCodes IBetaCodeService
supportTickets ISupportTicketService
options PanelRegistrationOptions
verification VerificationOptions
beta BetaOptions
throttle VerificationResendThrottle
selfService SelfServiceService
log ILogger<AccountRegistrationService>

Fields

CouldNotCreateError

The one refusal for a registration that could not be created, whatever the reason.

public const string CouldNotCreateError = "That account could not be created."

Field Value

string

InvalidBetaCodeError

The one refusal for any beta code problem. Passed through from the service's own wording.

public const string InvalidBetaCodeError = "That beta code is not valid."

Field Value

string

InvalidCodeError

The one answer to every code that does not verify: a wrong one, an expired one, an unknown account, an account already verified, and the third wrong code that opens a ticket.

public const string InvalidCodeError = "That verification code is not valid. After three incorrect codes a support ticket is opened for the account, and staff will contact you by email."

Field Value

string

Remarks

The verify endpoint is anonymous, so anything that differed between those cases would say which names exist, which are verified, and how many guesses an account has had. Saying up front what three wrong codes do costs nothing, because it is true of every account.

TwoFactorNotSetUpWarning

What a new account is told when it was created without two-factor.

public const string TwoFactorNotSetUpWarning = "Your account was created, but two-factor could not be set up on it. Sign in and set it up from My account."

Field Value

string

Methods

ChannelNames(AccountVerificationChannels)

Wire names for a set of channels: "email", "sms", "discord".

public static string[] ChannelNames(AccountVerificationChannels channels)

Parameters

channels AccountVerificationChannels

Returns

string[]

ParseChannel(string)

Parses a wire channel name, or None.

public static AccountVerificationChannels ParseChannel(string name)

Parameters

name string

Returns

AccountVerificationChannels

RegisterAsync(RegistrationInput, CancellationToken)

Creates an account from a browser-computed salt and verifier.

public Task<AccountRegistrationService.RegistrationResult> RegisterAsync(AccountRegistrationService.RegistrationInput input, CancellationToken cancellationToken = default)

Parameters

input AccountRegistrationService.RegistrationInput
cancellationToken CancellationToken

Returns

Task<AccountRegistrationService.RegistrationResult>

Remarks

The password is never a parameter here, and there is nowhere for it to arrive: the browser derives the salt and verifier with the same SRP rules the game client uses and sends only those, so this service could not log or leak a password if it tried.

ResendAsync(string, AccountVerificationChannels, CancellationToken)

Sends a fresh code for one channel, when the account is owed one.

public Task ResendAsync(string username, AccountVerificationChannels channel, CancellationToken cancellationToken = default)

Parameters

username string
channel AccountVerificationChannels
cancellationToken CancellationToken

Returns

Task

Remarks

Returns nothing, deliberately. The endpoint is anonymous and answers identically whatever happens here — unknown account, verified account, a channel it never chose, a cooldown still running — or it would say which names exist and what they chose.

A code still waiting in the queue is not replaced: generating a new one would invalidate the code in the message that is about to arrive.

Email and SMS only. The Discord code is delivered once, as one DM, and is never replaced — a second code would strand the first DM, and the bot never sends another — so the endpoint refuses a Discord resend before it gets here.

VerifyAsync(string, int, CancellationToken)

Redeems a verification code from any channel.

public Task<(bool Ok, string Error, bool Retry)> VerifyAsync(string username, int code, CancellationToken cancellationToken = default)

Parameters

username string
code int
cancellationToken CancellationToken

Returns

Task<(bool Ok, string Error, bool Retry)>

Remarks

PersistVerifiedByCodeAsync matches the code against every code the account holds — email, SMS and Discord — and checks the expiry, in one statement. Any one match verifies the account outright; there is no second code to ask for afterwards.

Every wrong code is counted through RecordAsync(IAccountService, ISupportTicketService?, string, CancellationToken), in the database the login server counts into, and the third in a row opens a support ticket. What that did is logged and never returned: the answer is InvalidCodeError whatever happened, so the endpoint cannot be used to learn anything about an account.

A wrong code, an unknown account and a verified one all come back from the service as the same VALIDATION_ERROR, so counting only that keeps every one of them identical. A database fault is not a wrong code: it used to be counted as one, so a correct code typed during an outage was told it was invalid and moved the account towards an automatic ticket. It is answered with "try again" instead — the same for every account, so it says nothing either.