Table of Contents

Class TokenGenerator

Namespace
Builvero.Infrastructure.Services
Assembly
Builvero.Infrastructure.dll

Implementation of ITokenGenerator using cryptographically secure random number generation.

public class TokenGenerator : ITokenGenerator
Inheritance
TokenGenerator
Implements
Inherited Members

Remarks

This implementation uses RandomNumberGenerator for all token and code generation, ensuring cryptographically secure randomness suitable for security-sensitive operations.

Methods

GenerateInvitationCode()

Generates an 8-character alphanumeric invitation code for user registration.

public string GenerateInvitationCode()

Returns

string

An 8-character string using uppercase letters and numbers (excluding ambiguous characters).

Remarks

Character set: "ABCDEFGHJKLMNPQRSTUVWXYZ23456789" (excludes 0, O, I, 1, L to reduce confusion). Uses cryptographically secure random bytes and maps them to the character set.

GenerateSecureToken()

Generates a secure 32-character alphanumeric token for email-based actions.

public string GenerateSecureToken()

Returns

string

A 32-character string using mixed-case letters and numbers (excluding ambiguous characters).

Remarks

Character set: "ABCDEFGHJKLMNPQRSTUVWXYZ23456789abcdefghjkmnpqrstuvwxyz" (excludes 0, O, I, 1, i, l, L). Uses cryptographically secure random bytes and maps them to the character set.

This token is used in email links for actions like invitation acceptance and join request approval, allowing users to perform actions without logging in first.

GenerateVerificationCode()

Generates a 6-digit numeric verification code for email verification.

public string GenerateVerificationCode()

Returns

string

A 6-digit numeric string (e.g., "123456").

Remarks

Uses GetInt32(int, int) to generate a random integer between 100000 and 999999, then formats it as a 6-digit string with leading zeros if necessary.