TwoFactor/TwoFactorLoginRequestValidator.cs

netrock · src/backend/MyProject.WebApi/Features/Authentication/Dtos/TwoFactor/TwoFactorLoginRequestValidator.cs · csharp · MIT
auth, Auth / Identity

Validates 2FA login request fields, ensuring token and code meet format requirements.

// Source: https://github.com/fpindej/netrock | License: MIT | Copyright 2025-2026 Filip Pindej
// Provided via justclaw.it.com; keep this notice with the code.
using FluentValidation;

namespace MyProject.WebApi.Features.Authentication.Dtos.TwoFactor;

/// <summary>
/// Validates <see cref="TwoFactorLoginRequest"/> fields at runtime.
/// </summary>
public class TwoFactorLoginRequestValidator : AbstractValidator<TwoFactorLoginRequest>
{
    /// <summary>
    /// Initializes validation rules for 2FA login requests.
    /// </summary>
    public TwoFactorLoginRequestValidator()
    {
        RuleFor(x => x.ChallengeToken)
            .NotEmpty()
            .MaximumLength(100);

        RuleFor(x => x.Code)
            .NotEmpty()
            .Length(6)
            .Matches(@"^\d{6}$").WithM

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key