Table of Contents

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
object
ServiceCollectionExtensions

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

services IServiceCollection

The service collection.

options Argon2idOptions

Optional 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.

pepper PepperRing

Optional PepperRing for keyed hashing. When null, any PepperRing previously registered in services is picked up at resolution time; otherwise no pepper is used.

Returns

IServiceCollection

The same services instance, for chaining.

Type Parameters

TUser

The Identity user type (e.g. IdentityUser).

Examples

builder.Services
    .AddIdentityCore<IdentityUser>()
    .Services
    .AddArgon2idPasswordHasher<IdentityUser>();

Exceptions

ArgumentNullException

services is 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

services IServiceCollection

The service collection.

configureOptions Action<Argon2idOptions>

Callback that mutates the Argon2idOptions instance the hasher will use. Invoked through IOptions<Argon2idOptions>.

Returns

IServiceCollection

The same services instance, for chaining.

Type Parameters

TUser

The 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

services or configureOptions is null.