Table of Contents

Class BetaCodeFormat

Namespace
FishMMO.Database.Data
Assembly
FishMMO-DB.dll

The shape of a beta code, and of the program name a batch of codes is minted under.

public static class BetaCodeFormat
Inheritance
BetaCodeFormat
Inherited Members

Remarks

Twelve characters from a 32-symbol alphabet with 0/O and 1/I removed, displayed as three groups of four. A code is read off an email or a forum post and typed by hand, and those are the pairs a player cannot tell apart in most fonts: a code that is valid but untypeable is a support ticket. 32^12 is 2^60, so guessing one is not a strategy even before the login server's rate limits.

The stored form is the displayed form, hyphens included. Every path that accepts a code from outside runs it through Normalize(string?) first, so abcd efgh jkmn and ABCD-EFGH-JKMN are one code and the unique index on beta_codes.code is over one spelling of it.

Fields

Alphabet

The symbols a code is drawn from: A–Z and 2–9 without O and I.

public const string Alphabet = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"

Field Value

string

CodeLength

Significant characters in a code, hyphens excluded.

public const int CodeLength = 12

Field Value

int

DisplayLength

Length of the displayed and stored form, XXXX-XXXX-XXXX.

public const int DisplayLength = 14

Field Value

int

GroupSize

Characters per displayed group.

public const int GroupSize = 4

Field Value

int

InvalidProgramError

The message for a program name that fails IsValidProgram(string?).

public const string InvalidProgramError = "A program name is 1 to 32 characters of lowercase letters, digits, hyphens and underscores."

Field Value

string

ProgramMaxLength

Longest program name.

public const int ProgramMaxLength = 32

Field Value

int

Methods

Generate()

Generates a new code in display form from a cryptographic random source.

public static string Generate()

Returns

string

Remarks

Rejection sampling rather than byte % 32: a byte that falls in the incomplete top range is thrown away, so every symbol is exactly equally likely. With a 32-symbol alphabet 256 divides evenly and nothing is ever rejected, but the loop stays correct if the alphabet is ever changed to a size that does not — which is exactly when a modulo would quietly start favouring the first few letters. RandomNumberGenerator.GetInt32 would do this for us, but it is .NET 6 and this assembly targets netstandard2.1.

IsValidProgram(string?)

Whether a program name is 1–32 characters of [a-z0-9_-].

public static bool IsValidProgram(string? program)

Parameters

program string

Returns

bool

Remarks

Tests the name as given; callers normalise with NormalizeProgram(string?) first. The name is an identifier the login server's configuration lists, so it is kept to characters that survive a config file, an environment variable and a URL without quoting.

Normalize(string?)

Canonicalises a code typed or pasted by a person.

public static string? Normalize(string? code)

Parameters

code string

The code as entered.

Returns

string

The code as XXXX-XXXX-XXXX, or null when it is not a well-formed code.

Remarks

Uppercases, drops hyphens and whitespace wherever they appear, and requires exactly twelve alphabet characters. Anything else — including a 0 or O the player believed they saw — is null rather than a best guess: silently mapping a mistyped symbol onto a valid one would turn a typo into somebody else's code.

NormalizeProgram(string?)

Trims and lowercases a program name. Null becomes the empty string, which is not valid.

public static string NormalizeProgram(string? program)

Parameters

program string

Returns

string

Remarks

Lowercased so "Closed-Beta" in a config file and "closed-beta" typed into the panel are one program: a mismatch here would lock every tester out while the codes looked fine.