Table of Contents

Class IdentityBuilderExtensions

Namespace
Argon2id.PasswordHasher.AspNetCore
Assembly
Argon2id.PasswordHasher.AspNetCore.dll

Extension methods that let callers wire the Argon2id hasher into the natural ASP.NET Core Identity builder chain.

public static class IdentityBuilderExtensions
Inheritance
object
IdentityBuilderExtensions

Examples

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

// Or with inline configuration:
builder.Services
    .AddIdentityCore<IdentityUser>()
    .AddArgon2idPasswordHasher<IdentityUser>(opts => opts.MemorySizeKib = 131072);

Methods

AddArgon2idPasswordHasherWithMigration<TUser>(IdentityBuilder)

Registers a MigratingPasswordHasher<TUser> as the IPasswordHasher<TUser>, using Argon2id for new hashes and the stock ASP.NET Core Identity PasswordHasher<TUser> (PBKDF2) to verify any stored hash that isn't already Argon2id. Successful legacy verifications return SuccessRehashNeeded so Identity transparently upgrades the stored value on the next sign-in.

public static IdentityBuilder AddArgon2idPasswordHasherWithMigration<TUser>(this IdentityBuilder builder) where TUser : class

Parameters

builder IdentityBuilder

The Identity builder being configured.

Returns

IdentityBuilder

The same builder, for chaining.

Type Parameters

TUser

The Identity user type.

Remarks

This is the recommended adapter when migrating an existing user store from the default ASP.NET Core Identity PBKDF2 hasher to Argon2id. See MIGRATION.md for the end-to-end story.

Exceptions

ArgumentNullException

builder is null.

AddArgon2idPasswordHasherWithMigration<TUser>(IdentityBuilder, Action<Argon2idOptions>)

AddArgon2idPasswordHasherWithMigration<TUser>(IdentityBuilder) with inline configuration of the Argon2id options.

public static IdentityBuilder AddArgon2idPasswordHasherWithMigration<TUser>(this IdentityBuilder builder, Action<Argon2idOptions> configureOptions) where TUser : class

Parameters

builder IdentityBuilder

The Identity builder being configured.

configureOptions Action<Argon2idOptions>

Callback that mutates the Argon2id options.

Returns

IdentityBuilder

The same builder, for chaining.

Type Parameters

TUser

The Identity user type.

Exceptions

ArgumentNullException

builder or configureOptions is null.

AddArgon2idPasswordHasher<TUser>(IdentityBuilder)

Registers the Argon2id hasher as the IPasswordHasher<TUser> for TUser. Uses the library's recommended defaults unless a previous services.Configure<Argon2idOptions>(...) call says otherwise.

public static IdentityBuilder AddArgon2idPasswordHasher<TUser>(this IdentityBuilder builder) where TUser : class

Parameters

builder IdentityBuilder

The Identity builder being configured.

Returns

IdentityBuilder

The same builder, for chaining.

Type Parameters

TUser

The Identity user type. Must match the type passed to AddIdentityCore<TUser>(); a mismatch throws.

Exceptions

ArgumentNullException

builder is null.

InvalidOperationException

TUser does not match the user type of builder.

AddArgon2idPasswordHasher<TUser>(IdentityBuilder, Action<Argon2idOptions>)

Registers the Argon2id hasher and configures its options inline. Same chaining pattern as AddArgon2idPasswordHasher<TUser>(IdentityBuilder).

public static IdentityBuilder AddArgon2idPasswordHasher<TUser>(this IdentityBuilder builder, Action<Argon2idOptions> configureOptions) where TUser : class

Parameters

builder IdentityBuilder

The Identity builder being configured.

configureOptions Action<Argon2idOptions>

Callback that mutates the options.

Returns

IdentityBuilder

The same builder, for chaining.

Type Parameters

TUser

The Identity user type. Must match the type passed to AddIdentityCore<TUser>(); a mismatch throws.

Exceptions

ArgumentNullException

builder or configureOptions is null.

InvalidOperationException

TUser does not match the user type of builder.