Soenneker.Validators.BasicAuth
4.0.210
Prefix Reserved
See the version list below for details.
dotnet add package Soenneker.Validators.BasicAuth --version 4.0.210
NuGet\Install-Package Soenneker.Validators.BasicAuth -Version 4.0.210
<PackageReference Include="Soenneker.Validators.BasicAuth" Version="4.0.210" />
<PackageVersion Include="Soenneker.Validators.BasicAuth" Version="4.0.210" />
<PackageReference Include="Soenneker.Validators.BasicAuth" />
paket add Soenneker.Validators.BasicAuth --version 4.0.210
#r "nuget: Soenneker.Validators.BasicAuth, 4.0.210"
#:package Soenneker.Validators.BasicAuth@4.0.210
#addin nuget:?package=Soenneker.Validators.BasicAuth&version=4.0.210
#tool nuget:?package=Soenneker.Validators.BasicAuth&version=4.0.210
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 | Versions 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. |
-
net10.0
- Soenneker.Extensions.Configuration (>= 4.0.869)
- Soenneker.Hashing.Pbkdf2 (>= 4.0.31)
- Soenneker.Security.Parsers.BasicAuth (>= 4.0.24)
- Soenneker.Security.Util (>= 4.0.38)
- Soenneker.Validators.Validator (>= 4.0.734)
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 |
Update dependency Soenneker.Extensions.Configuration to 4.0.869 (#473)