Soenneker.Validators.BasicAuth 4.0.209

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 4.0.209
                    
NuGet\Install-Package Soenneker.Validators.BasicAuth -Version 4.0.209
                    
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="4.0.209" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Validators.BasicAuth" Version="4.0.209" />
                    
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 4.0.209
                    
#r "nuget: Soenneker.Validators.BasicAuth, 4.0.209"
                    
#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@4.0.209
                    
#: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=4.0.209
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Validators.BasicAuth&version=4.0.209
                    
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 net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
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
4.0.213 0 9/1/2026
4.0.212 30 8/31/2026
4.0.211 31 8/31/2026
4.0.210 46 8/31/2026
4.0.209 32 8/31/2026
4.0.208 40 8/30/2026
4.0.207 46 8/30/2026
4.0.206 56 8/30/2026
4.0.205 54 8/30/2026
4.0.204 40 8/30/2026
4.0.203 44 8/29/2026
4.0.202 39 8/29/2026
4.0.200 118 8/26/2026
4.0.199 63 8/26/2026
4.0.198 54 8/25/2026
4.0.197 122 8/21/2026
4.0.196 233 8/18/2026
4.0.195 164 8/13/2026
4.0.194 114 8/13/2026
4.0.193 90 8/12/2026
Loading failed

Update dependency Soenneker.Hashing.Pbkdf2 to 4.0.31 (#472)