Class ServiceCollectionExtensions
- Namespace
- Argon2id.PasswordHasher.AspNetCore
- Assembly
- Argon2id.PasswordHasher.AspNetCore.dll
Dependency-injection helpers for registering the Argon2id password hasher with ASP.NET Core Identity.
public static class ServiceCollectionExtensions
- Inheritance
-
objectServiceCollectionExtensions
Methods
AddArgon2idPasswordHasher<TUser>(IServiceCollection, Argon2idOptions?, PepperRing?)
Registers the secure-by-default Argon2id hasher as the IPasswordHasher<TUser> for ASP.NET Core Identity.
public static IServiceCollection AddArgon2idPasswordHasher<TUser>(this IServiceCollection services, Argon2idOptions? options = null, PepperRing? pepper = null) where TUser : class
Parameters
servicesIServiceCollectionThe service collection.
optionsArgon2idOptionsOptional Argon2id work-factor parameters. When null the hasher resolves Argon2idOptions from IOptions<TOptions>, so a prior
services.Configure<Argon2idOptions>(...)call wins. If neither is set, Recommended is used.pepperPepperRingOptional PepperRing for keyed hashing. When null, any PepperRing previously registered in
servicesis picked up at resolution time; otherwise no pepper is used.
Returns
- IServiceCollection
The same
servicesinstance, for chaining.
Type Parameters
TUserThe Identity user type (e.g.
IdentityUser).
Examples
builder.Services
.AddIdentityCore<IdentityUser>()
.Services
.AddArgon2idPasswordHasher<IdentityUser>();
Exceptions
- ArgumentNullException
servicesis null.
AddArgon2idPasswordHasher<TUser>(IServiceCollection, Action<Argon2idOptions>)
Registers the Argon2id hasher and configures its options inline via the
standard .NET Options pattern. Use this overload when you want to read
settings from IConfiguration:
public static IServiceCollection AddArgon2idPasswordHasher<TUser>(this IServiceCollection services, Action<Argon2idOptions> configureOptions) where TUser : class
Parameters
servicesIServiceCollectionThe service collection.
configureOptionsAction<Argon2idOptions>Callback that mutates the Argon2idOptions instance the hasher will use. Invoked through
IOptions<Argon2idOptions>.
Returns
- IServiceCollection
The same
servicesinstance, for chaining.
Type Parameters
TUserThe Identity user type.
Examples
// Inline:
builder.Services.AddArgon2idPasswordHasher<IdentityUser>(opts =>
{
opts.MemorySizeKib = 131072;
opts.Iterations = 4;
});
// From appsettings.json (section "Argon2id"):
builder.Services.AddArgon2idPasswordHasher<IdentityUser>(opts =>
builder.Configuration.GetSection("Argon2id").Bind(opts));
Exceptions
- ArgumentNullException
servicesorconfigureOptionsis null.