Covers secure password storage: per-user salts, optional pepper, tunable work factors, PBKDF2 vs bcrypt vs Argon2id, Identity's versioned PasswordHasher and migrating legacy hashes by wrapping and rehash-on-login.
Never store the password or a fast hash of it. Store the output of a slow, salted password hashing function: a random salt per user (so identical passwords differ and rainbow tables fail) and a work factor that makes each guess cost tens of milliseconds. For new systems OWASP recommends Argon2id because it is memory-hard; where FIPS 140 validation is required, PBKDF2-HMAC-SHA512 is the right choice, and it is what ASP.NET Core Identity's PasswordHasher<TUser> uses (100,000 iterations by default since .NET 7, raisable, versioned so old hashes keep verifying). An optional pepper kept in Key Vault means a database-only leak isn't enough.
To fix a legacy MD5 or SHA-1 table, wrap every old hash now (PBKDF2(oldHash)) and rehash on next successful login. Hashing only protects you after a breach, so pair it with lockout and rate limiting on login. The trade-off is login CPU versus attacker cost.
"The threat model is an offline attack after a breach: the attacker has the table and guesses passwords as fast as their hardware allows. So storage has three jobs. A per-user random salt so each guess only tests one account and rainbow tables are useless. A work factor so each guess is slow: I aim for something like 50 to 250 milliseconds on our production hardware. And ideally memory hardness, so GPUs and ASICs don't get a huge advantage. That points to Argon2id, with PBKDF2-HMAC-SHA512 at a high iteration count when we need FIPS-validated primitives, and bcrypt as an acceptable legacy choice with its 72-byte input limit.
In ASP.NET Core I start with Identity's
PasswordHasher<TUser>. It writes a versioned string: format marker, PRF, iteration count, salt and subkey. Today that is PBKDF2 with HMAC-SHA512 and 100,000 iterations, and because the count is stored in the hash I can raisePasswordHasherOptions.IterationCountand old hashes still verify.VerifyHashedPasswordreturnsSuccessRehashNeededand Identity'sSignInManagerrehashes for me. If I want Argon2id I implementIPasswordHasher<TUser>and keep verifying the old format.For example, at [company] we inherited [a membership table with unsalted SHA-1 for about 300,000 users]. I didn't wait for logins: in one migration we computed
PBKDF2(SHA1hash)for every row and tagged it as version 'wrapped', so nothing weak was left at rest the same day. Then on each successful login we verified through the wrapper and rehashed the plain password natively. [Within 60 days roughly 70%] were native; the rest got a forced reset email.The mistake I see is focusing on the algorithm and forgetting the rest: no lockout or rate limiting on login, hashes compared with
==, or passwords leaking into logs before they're ever hashed. Strong hashing buys time after a breach; it doesn't stop online guessing."
| Algorithm | Strength | Weakness | Suggested parameters (OWASP Password Storage Cheat Sheet) |
|---|---|---|---|
| Argon2id | Memory-hard, GPU-resistant | Not in the BCL, needs a vetted package | m = 19 MiB, t = 2, p = 1 (or more memory) |
| scrypt | Memory-hard | Less common in .NET | N = 2^17, r = 8, p = 1 |
| bcrypt | Battle-tested, simple | 72-byte input limit, not memory-hard | cost 10 or more |
| PBKDF2-HMAC-SHA512 | FIPS-validated, in the BCL | Not memory-hard, needs high iterations | about 210,000 iterations |
| SHA-x / MD5 (even salted) | Fast | Fast | Never |
| Salt | Pepper | |
|---|---|---|
| Secret? | No, stored beside the hash | Yes, in Key Vault or an HSM |
| Unique? | Per password | Per application (versioned) |
| Defends against | Rainbow tables, parallel cracking | A database-only leak (SQL injection, backup theft) |
| Cost | None | Key management and rotation complexity |
user.PasswordHash = Convert.ToHexString(SHA1.HashData(Encoding.UTF8.GetBytes(password)));user.PasswordHash = passwordHasher.HashPassword(user, password); plus lockout and rate limiting on the login endpoint.A password table leak is very likely an eligible data breach under the Notifiable Data Breaches scheme, and APP 11 requires "reasonable steps" to protect personal information. Weak hashing makes "serious harm is unlikely" impossible to argue.
Raising PBKDF2 from [10,000 to 210,000] iterations moved our verify time from [about 4 ms to about 80 ms] on [B2s App Service instances]. Login p95 went up [70 ms], which nobody noticed, and we added a fixed-window rate limiter of [5 attempts per minute per account and IP] so the extra CPU couldn't be used as a DoS lever.
Checks whether the candidate can design password storage end to end, including parameters, upgrade paths and the online-attack side.
Green flags
Red flags
The defender pays the work factor once per login; the attacker pays it once per guess per account.
Cost to crack one account = (guesses needed) x (time per hash) / (attacker's parallel units)
^ you control this
Raise the time per hash 1,000x and you raise the attacker's cost 1,000x while your login gets maybe 50 ms slower.
PBKDF2 is just HMAC repeated N times. A GPU has thousands of cores with little memory each, so it parallelises PBKDF2 well. Argon2id fills a large memory block (e.g. 19 MiB) and reads it in a data-dependent pattern, so each guess needs that memory: the GPU can run far fewer guesses at once.
byte 0 : 0x01 (V3 format marker)
bytes 1-4 : PRF (KeyDerivationPrf: 2 = HMACSHA512)
bytes 5-8 : iteration count (big-endian)
bytes 9-12 : salt length (16)
bytes 13-28 : salt
bytes 29-60 : derived subkey (32 bytes)
-> Base64 encoded into AspNetUsers.PasswordHash
VerifyHashedPassword reads the parameters from the stored hash, recomputes, compares with CryptographicOperations.FixedTimeEquals, and returns SuccessRehashNeeded when the stored iteration count or PRF is below the current options. V2 hashes (PBKDF2-SHA1, 1,000 iterations, from ASP.NET Identity 2) still verify when CompatibilityMode allows it, and get upgraded.
Apply the pepper as an HMAC before the slow hash: Argon2id(HMACSHA256(pepper, password), salt). Store a pepper version with each hash so you can rotate: new hashes use v2, old ones verify with v1 and are rehashed on login. Never just concatenate, and never put the pepper in the same database.
Day 0 : every row -> hash = PBKDF2(legacyHash, newSalt), format = "wrapped-sha1"
Login : verify PBKDF2(SHA1(input), salt) == hash
on success -> hash = native(input), format = "v3"
Day 90 : remaining wrapped rows -> force reset, then delete the format
Wrapping removes the weak hash from storage immediately, which matters if the breach happens before users log in.
Offline cracking is half the story. Credential stuffing uses passwords leaked elsewhere. Defences: lockout (LockoutOptions), ASP.NET Core rate limiting, checking new passwords against known-breached lists (k-anonymity range queries to Have I Been Pwned), and MFA.
PasswordHasher<object>.HashPassword at 100,000, 210,000 and 600,000 iterations with BenchmarkDotNet on your laptop and on a small cloud VM.IterationCount, log in with an old account, and confirm the PasswordHash column changes.IPasswordHasher<TUser> that verifies a wrapped-sha1 format and returns SuccessRehashNeeded.Raising Identity's work factor, and a hasher that upgrades wrapped legacy SHA-1 hashes on login.
// Program.cs
builder.Services.Configure<PasswordHasherOptions>(o =>
{
o.CompatibilityMode = PasswordHasherCompatibilityMode.IdentityV3;
o.IterationCount = 210_000; // stored in each hash, so raising it is safe
});
builder.Services.AddScoped<IPasswordHasher<AppUser>, LegacyAwarePasswordHasher>();
using System.Security.Cryptography;
using System.Text;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Options;
namespace Accounts.Security;
public sealed class AppUser : IdentityUser;
// Legacy rows were migrated on day 0 to: "wrapped-sha1$<base64 salt>$<base64 PBKDF2(SHA1(pw))>"
public sealed class LegacyAwarePasswordHasher(IOptions<PasswordHasherOptions> options)
: IPasswordHasher<AppUser>
{
private const string WrappedPrefix = "wrapped-sha1$";
private readonly PasswordHasher<AppUser> _inner = new(options);
public string HashPassword(AppUser user, string password) => _inner.HashPassword(user, password);
public PasswordVerificationResult VerifyHashedPassword(AppUser user, string hashedPassword, string providedPassword)
{
if (!hashedPassword.StartsWith(WrappedPrefix, StringComparison.Ordinal))
return _inner.VerifyHashedPassword(user, hashedPassword, providedPassword);
var parts = hashedPassword[WrappedPrefix.Length..].Split('$');
byte[] salt = Convert.FromBase64String(parts[0]);
byte[] expected = Convert.FromBase64String(parts[1]);
byte[] legacy = SHA1.HashData(Encoding.UTF8.GetBytes(providedPassword)); // the old weak step
byte[] actual = Rfc2898DeriveBytes.Pbkdf2(legacy, salt, 210_000, HashAlgorithmName.SHA512, expected.Length);
// Constant time, then ask Identity to store a native V3 hash.
return CryptographicOperations.FixedTimeEquals(actual, expected)
? PasswordVerificationResult.SuccessRehashNeeded
: PasswordVerificationResult.Failed;
}
}
SHA256(salt + password)) and calling it done. Why it is wrong: the salt stops rainbow tables, but each guess is still nanoseconds. Instead: use a slow KDF with a tuned work factor.LockoutOptions (e.g. 5 failures, 15 minutes), add an ASP.NET Core rate limiter per account and IP, and offer MFA.The strongest move is often not to store passwords at all: delegate to Entra ID or Entra External ID, or go passwordless with passkeys. When you must own them, Identity's defaults are good enough for most systems, and your effort is better spent on rate limiting, MFA and breached-password checks than on swapping PBKDF2 for Argon2id.
| Option | When it fits | Cost | When not |
|---|---|---|---|
Identity PasswordHasher (PBKDF2) |
Most ASP.NET Core apps, FIPS needs | Zero code | When policy mandates memory-hard hashing |
Custom Argon2id IPasswordHasher |
High-value targets, security-led orgs | A vetted dependency, memory per login | Tight memory budgets under login bursts |
| External IdP / passkeys | Customer and workforce identity at scale | Licence, integration | Offline or air-gapped systems |
Measure it: hash time per instance, login CPU during a spike, and the share of hashes still on old formats (a simple query on the format prefix) as a migration metric.
ASP.NET Core Identity is a membership library: user and role stores (usually EF Core), password hashing with PasswordHasher (PBKDF2 with HMAC-SHA512 and 100,000 iterations), lockout after failed attempts, email confirmation, password reset tokens, two-factor with authenticator apps and recovery codes, the security stamp, and since .NET 10 passkeys. MapIdentityApi adds ready-made register, login and refresh endpoints for SPAs and mobile apps.
Use it when one app owns its own users. Choose an external identity provider (Microsoft Entra ID for staff, Entra External ID, Auth0 or similar for customers) when you need single sign-on across apps, federation with other organisations, conditional access, or you don't want to own password security and compliance yourself.
The trade-off: Identity is free and fully in your control, but every security feature and incident is yours to run.
MFA methods differ mainly in phishing resistance.
ASP.NET Core Identity in .NET 10 supports passkey registration and sign-in (MakePasskeyCreationOptionsAsync, PerformPasskeyAttestationAsync, PasskeySignInAsync). The ACSC Essential Eight has required phishing-resistant MFA from Maturity Level 2 since its November 2023 update.
The trade-off: passkeys are the strongest and easiest for users, but account recovery and device loss need careful design.
How to tell it (STAR)
**S:** At [company] a pen test found our [customer portal] still stored unsalted SHA-1 password hashes, and a backup was reachable from [a public storage container]. **T:** I owned closing the finding without forcing [300,000] users through a reset in one go. **A:** I locked down the storage within the hour, then wrote a migration that wrapped every legacy hash in PBKDF2 so nothing weak stayed at rest, and a custom `IPasswordHasher` that verified the wrapped format and returned `SuccessRehashNeeded` so Identity upgraded users as they signed in. I worked with [the privacy officer] on the NDB assessment and added login rate limiting. **R:** The retest cracked [0] hashes, [about 70%] of active users were on native hashes within [60 days], and the rest went through a targeted reset with [under 2%] support contacts.
Last updated 23 Nov 2026.