Table of Contents

Struct UserCredentialUsername

Namespace
MailFathom.Domain.Access
Assembly
MailFathom.Domain.dll

The name one user credential is looked up by, in the single form the deployment stores and compares.

public readonly record struct UserCredentialUsername : IEquatable<UserCredentialUsername>
Implements
Inherited Members

Remarks

A username is not an identity and names no person: it is the handle a caller writes into an HTTP Basic credential, and what it resolves to is one credential row belonging to one UserId. Two credentials may belong to one user and be rotated apart; no two may carry one username, which is what makes the lookup a single indexed read rather than a scan that could match twice.

Canonical form is the whole reason this is a type. A username arrives from a person typing it into a client, so it arrives with the capitalization and the surrounding space that a person's keyboard produced, while the column it is matched against holds exactly one spelling. Folding is done here — trimmed, then lowercased under the invariant culture — so that the form stored at provisioning, the form the unique index enforces, and the form a request is resolved by are one form decided in one place. Culture-sensitive lowercasing is deliberately not used: a deployment whose process culture changed would otherwise fold two different sets of names and stop resolving credentials it had already issued.

The accepted characters are the conservative set an operator can type, quote, and read back out of a log without escaping: letters, digits, and ., -, _, +, and @. A colon is refused outright and is the one refusal that is about the transport rather than about tidiness — RFC 7617 separates the username from the password with the first colon, so a username carrying one could never be presented whole and would silently authenticate as a shorter name.

Being a struct, default is reachable and is not a username. It reports itself through IsSpecified and refuses to answer for a value, and the only ways to obtain one are the two factories below.

Fields

MaximumLength

The longest username this deployment accepts, in characters of its canonical form.

Properties

IsSpecified

Gets whether this value names a username rather than the unusable struct default.

Value

Gets the canonical form, which is what is stored, indexed, and compared.

Methods

Create(string)

Reads a written username into its canonical form, refusing anything this deployment does not accept.

DescribeAcceptedForm()

Describes what a written username may contain, for a refusal an operator reads.

ToString()

Returns the fully qualified type name of this instance.

TryCreate(string?, out UserCredentialUsername)

Reads a written username into its canonical form.