Soenneker.Validators.BasicAuth 11.0.271

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Soenneker.Validators.BasicAuth --version 11.0.271
                    
NuGet\Install-Package Soenneker.Validators.BasicAuth -Version 11.0.271
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Soenneker.Validators.BasicAuth" Version="11.0.271" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Validators.BasicAuth" Version="11.0.271" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Validators.BasicAuth" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Soenneker.Validators.BasicAuth --version 11.0.271
                    
#r "nuget: Soenneker.Validators.BasicAuth, 11.0.271"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Soenneker.Validators.BasicAuth@11.0.271
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Soenneker.Validators.BasicAuth&version=11.0.271
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Validators.BasicAuth&version=11.0.271
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

Soenneker.Validators.BasicAuth

Validates HTTP Basic Authentication credentials against a fixed-cost username comparison and a PBKDF2 PHC password hash.

Install

dotnet add package Soenneker.Validators.BasicAuth

Registration

using Soenneker.Validators.BasicAuth.Registrars;
using Microsoft.Extensions.DependencyInjection;

services.AddBasicAuthValidatorAsSingleton();

The validator is stateless, so singleton registration is appropriate for most applications. AddBasicAuthValidatorAsScoped() is also available.

Configuration

{
  "BasicAuth": {
    "Username": "integration-client",
    "PasswordPhc": "<PBKDF2 PHC hash>"
  }
}

Generate and store the PHC hash rather than a plaintext password:

using Soenneker.Hashing.Pbkdf2;

string passwordPhc = Pbkdf2HashingUtil.Hash("replace-with-secret-input");

Keep the resulting configuration value in a secret store. The validator reads BasicAuth:Username and BasicAuth:PasswordPhc when the corresponding method argument is null.

Validate a request

using Soenneker.Validators.BasicAuth.Abstract;

if (!validator.ValidateSafe(httpContext))
{
    httpContext.Response.StatusCode = StatusCodes.Status401Unauthorized;
    return;
}

ValidateSafe returns false when the request lacks parseable Basic credentials or the username/password does not match. Required-configuration failures and invalid PHC data still throw; “safe” applies to request authentication failures, not application misconfiguration.

Use Validate when invalid request credentials should throw UnauthorizedAccessException:

validator.Validate(httpContext);

Both methods return true on success and use the same generic "Invalid credentials" exception message for strict request failures.

Per-call overrides

bool valid = validator.ValidateSafe(
    httpContext,
    configuredUsername: expectedUsername,
    configuredPasswordPhc: expectedPasswordPhc);

Overrides take precedence independently. A null argument falls back to configuration; it does not disable that credential check.

Security boundaries

Basic Authentication transmits a reusable username and password on every request. Require TLS, apply rate limiting where credentials can be guessed, and never log the authorization header or plaintext password. This validator clears the parser's temporary credential buffer after each attempt, compares usernames with fixed-cost UTF-8 comparison, and verifies passwords against the configured PBKDF2 PHC hash.

The validator authenticates one configured credential pair. It does not issue a challenge header, create a ClaimsPrincipal, authorize roles, rotate secrets, or replace ASP.NET Core authentication middleware when a full authentication scheme is needed.

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Soenneker.Validators.BasicAuth:

Package Downloads
Soenneker.Hangfire.BasicAuthentication

Protects the Hangfire dashboard with PBKDF2-backed HTTP Basic authentication

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
11.0.280 135 11/3/2026
11.0.279 162 10/27/2026
11.0.278 96 10/27/2026
11.0.277 100 10/27/2026
11.0.276 117 10/27/2026
11.0.275 99 10/26/2026
11.0.274 94 10/26/2026
11.0.273 120 10/26/2026
11.0.272 101 10/26/2026
11.0.271 103 10/26/2026
4.0.270 117 10/26/2026
4.0.269 126 10/23/2026
4.0.268 136 10/15/2026
4.0.267 109 10/15/2026
4.0.266 104 10/15/2026
4.0.265 111 10/14/2026
4.0.264 123 10/14/2026
4.0.262 110 10/14/2026
4.0.261 121 10/14/2026
4.0.255 117 10/13/2026
Loading failed

Merge remote-tracking branch 'origin/main'

# Conflicts:
# test/Soenneker.Validators.BasicAuth.Tests/Soenneker.Validators.BasicAuth.Tests.csproj