Soenneker.Validators.BasicAuth 4.0.234

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.234
                    
NuGet\Install-Package Soenneker.Validators.BasicAuth -Version 4.0.234
                    
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.234" />
                    
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.234" />
                    
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.234
                    
#r "nuget: Soenneker.Validators.BasicAuth, 4.0.234"
                    
#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.234
                    
#: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.234
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Validators.BasicAuth&version=4.0.234
                    
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.235 0 9/15/2026
4.0.234 37 9/14/2026
4.0.233 47 9/13/2026
4.0.232 51 9/13/2026
4.0.231 48 9/13/2026
4.0.230 69 9/13/2026
4.0.229 52 9/12/2026
4.0.226 91 9/9/2026
4.0.225 72 9/9/2026
4.0.224 81 9/8/2026
4.0.223 100 9/8/2026
4.0.222 100 9/8/2026
4.0.221 118 9/7/2026
4.0.220 108 9/7/2026
4.0.218 127 9/7/2026
4.0.217 115 9/5/2026
4.0.216 129 9/4/2026
4.0.215 101 9/4/2026
4.0.214 110 9/4/2026
4.0.213 134 9/1/2026
Loading failed

Merge pull request #492 from soenneker/renovate/soenneker.validators.validator-4.x

Update dependency Soenneker.Validators.Validator to 4.0.740