Soenneker.Security.Parsers.BasicAuth
4.0.25
Prefix Reserved
dotnet add package Soenneker.Security.Parsers.BasicAuth --version 4.0.25
NuGet\Install-Package Soenneker.Security.Parsers.BasicAuth -Version 4.0.25
<PackageReference Include="Soenneker.Security.Parsers.BasicAuth" Version="4.0.25" />
<PackageVersion Include="Soenneker.Security.Parsers.BasicAuth" Version="4.0.25" />
<PackageReference Include="Soenneker.Security.Parsers.BasicAuth" />
paket add Soenneker.Security.Parsers.BasicAuth --version 4.0.25
#r "nuget: Soenneker.Security.Parsers.BasicAuth, 4.0.25"
#:package Soenneker.Security.Parsers.BasicAuth@4.0.25
#addin nuget:?package=Soenneker.Security.Parsers.BasicAuth&version=4.0.25
#tool nuget:?package=Soenneker.Security.Parsers.BasicAuth&version=4.0.25
Soenneker.Security.Parsers.BasicAuth
A low-allocation parser for HTTP Basic credentials in an ASP.NET Core HttpContext.
Installation
dotnet add package Soenneker.Security.Parsers.BasicAuth
Usage
The returned spans point into a pooled character buffer. Always return that buffer in a finally block after the last credential comparison:
using System.Security.Cryptography;
using System.Text;
using Soenneker.Security.Parsers.BasicAuth;
char[]? credentialBuffer = null;
try
{
if (!BasicAuthParser.TryReadBasicCredentials(
httpContext,
out ReadOnlySpan<char> username,
out ReadOnlySpan<char> password,
out credentialBuffer))
{
return Results.Unauthorized();
}
bool usernameMatches = username.SequenceEqual(configuredUsername);
byte[] suppliedPassword = Encoding.UTF8.GetBytes(password);
try
{
bool passwordMatches = CryptographicOperations.FixedTimeEquals(
suppliedPassword,
configuredPasswordUtf8);
return usernameMatches && passwordMatches
? Results.Ok()
: Results.Unauthorized();
}
finally
{
CryptographicOperations.ZeroMemory(suppliedPassword);
}
}
finally
{
BasicAuthParser.Clear(credentialBuffer);
}
configuredPasswordUtf8 should be prepared outside the request path and protected like the original secret. In most applications, validate a password through the application's password hasher or identity provider rather than storing a reversible plaintext credential.
Parsing behavior
- Reads the first
Authorizationheader value and accepts theBasicscheme case-insensitively. - Rejects missing or malformed Base64, headers above 8 KiB, and decoded credentials without a non-empty username and password separated by the first colon.
- Allows additional colons in the password.
- Returns spans rather than username/password strings, avoiding immutable secret strings during parsing.
- On success, transfers one rented character buffer to the caller. Call
BasicAuthParser.Clearexactly once after the spans are no longer used. - On failure, clears and returns any buffer it rented; the returned buffer value is
null.
Basic authentication only Base64-encodes credentials; it does not encrypt them. Accept it only over HTTPS, avoid logging the header or decoded values, and apply rate limiting and credential-rotation controls appropriate to the endpoint.
| 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
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Soenneker.Security.Parsers.BasicAuth:
| Package | Downloads |
|---|---|
|
Soenneker.Validators.BasicAuth
A lightweight validation module for validating HTTP Basic Authentication credentials. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.25 | 175 | 8/30/2026 |
| 4.0.24 | 255 | 8/29/2026 |
| 4.0.23 | 84 | 8/29/2026 |
| 4.0.22 | 1,106 | 7/27/2026 |
| 4.0.21 | 287 | 7/21/2026 |
| 4.0.20 | 225 | 7/16/2026 |
| 4.0.19 | 1,000 | 6/18/2026 |
| 4.0.18 | 827 | 6/5/2026 |
| 4.0.15 | 1,449 | 3/12/2026 |
| 4.0.14 | 126 | 3/12/2026 |
| 4.0.12 | 307 | 3/12/2026 |
| 4.0.11 | 357 | 3/10/2026 |
| 4.0.10 | 317 | 3/9/2026 |
| 4.0.9 | 118 | 3/9/2026 |
| 4.0.8 | 127 | 3/9/2026 |
| 4.0.7 | 451 | 3/4/2026 |
| 4.0.6 | 1,401 | 1/2/2026 |
| 4.0.5 | 869 | 11/21/2025 |
| 4.0.4 | 839 | 10/29/2025 |
| 3.0.3 | 755 | 9/4/2025 |
Secure Basic Auth parser buffer handling