ASP.NET Core Identity's features (user store, PasswordHasher, lockout, 2FA, passkeys, MapIdentityApi) and the decision between Identity and an external identity provider.
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.
"ASP.NET Core Identity is Microsoft's membership system. You get a user model, stores for users, roles, claims, logins and tokens, normally backed by EF Core, and the managers that use them:
UserManager,SignInManagerandRoleManager. The security pieces are the part people underestimate. Passwords are hashed withPasswordHasher, which in its current V3 format uses PBKDF2 with HMAC-SHA512, 100,000 iterations and a random salt, and it rehashes older formats when the user signs in. There's lockout, five failed attempts locks the account for five minutes by default, as long as you passlockoutOnFailure: true. There's email confirmation, reset tokens, two-factor with TOTP authenticator apps and recovery codes, a security stamp that invalidates cookies when credentials change, and in .NET 10, passkeys.MapIdentityApiexposes JSON endpoints like/register,/loginand/refreshso a SPA or mobile app can use cookies or Identity's own opaque bearer tokens.When to use it: a single application that owns its users, like a small SaaS or an internal tool that can't use the company directory. When not to: as soon as you need single sign-on across several apps, partners signing in with their own organisation's accounts, or conditional access and risk-based sign-in. Then I'd use an external identity provider: Microsoft Entra ID for workforce users, and for customers Entra External ID, Auth0 or a self-hosted server like Duende IdentityServer or OpenIddict. Identity can still sit behind those as the user store.
The mistake I see is treating
MapIdentityApias an OAuth server. Its bearer tokens are proprietary, it has no consent, scopes or third-party clients. The senior line: Identity is a good user store; an identity provider is a product you operate."
| Feature | API | Default |
|---|---|---|
| Password hashing | IPasswordHasher<TUser> |
PBKDF2-HMAC-SHA512, 100,000 iterations, 128-bit salt (V3) |
| Password rules | PasswordOptions |
Length 6, digit, upper, lower, non-alphanumeric (raise length, drop composition rules) |
| Lockout | LockoutOptions |
5 attempts, 5 minutes, enabled for new users |
| Two-factor | GetAuthenticatorKeyAsync, VerifyTwoFactorTokenAsync |
TOTP (RFC 6238), recovery codes |
| Passkeys (.NET 10) | SignInManager.PasskeySignInAsync, MakePasskeyCreationOptionsAsync |
Requires schema version 3 |
| Security stamp | UpdateSecurityStampAsync, SecurityStampValidator |
Revalidated every 30 minutes |
| API endpoints | MapIdentityApi<TUser>() |
Cookies or opaque bearer tokens |
| Need | Identity | External IdP |
|---|---|---|
| One app, own users | Good fit | Possible, more setup |
| SSO across many apps | Hard | Built in |
| Staff with Microsoft 365 accounts | Wrong tool | Entra ID |
| B2B federation, social logins | External logins only | Built in |
| Conditional access, risk detection | Build yourself | Built in |
| Third-party API clients (OAuth scopes, consent) | No | Yes |
For [an internal scheduling app] with [~300] contractor users who had no company accounts, we used Identity with EF Core, TOTP 2FA and a 12-character minimum password. A year later the business wanted single sign-on with [two other apps], so we moved sign-in to [Entra External ID] and kept Identity's tables only for app-specific profile data.
Checks that the candidate knows what Identity really does for security and can make a sound build-vs-buy decision for identity.
Green flags
MapIdentityApi is not an OIDC serverRed flags
SignInManager --> UserManager --> IUserStore / IUserPasswordStore / IUserLockoutStore ...
| | '-- EF Core: AspNetUsers, AspNetUserLogins, AspNetUserPasskeys ...
| '-- IPasswordHasher, IUserValidator, IPasswordValidator, token providers
'-- cookie schemes: Identity.Application, Identity.External, Identity.TwoFactorUserId
Identity is not an authentication handler by itself; it signs users in with cookie schemes it registers, or with its bearer token scheme for MapIdentityApi.
The V3 hash is one base64 string: a format marker 0x01, the PRF (HMAC-SHA512), the iteration count, the salt length, the salt and the subkey. Because parameters are stored with the hash, VerifyHashedPassword can return SuccessRehashNeeded and SignInManager upgrades the stored hash after a successful sign-in. The iteration count rose from 10,000 (HMAC-SHA256) to 100,000 (HMAC-SHA512) in .NET 7.
Lockout protects one account from guessing, but credential stuffing tries one password across many accounts. Pair lockout with rate limiting by IP and by username, breached-password checks (for example the k-anonymity Pwned Passwords API) and, best of all, MFA or passkeys.
Added in .NET 8 for SPAs and mobile clients: /register, /login (?useCookies=true for a cookie), /refresh, /confirmEmail, /forgotPassword, /resetPassword, /manage/2fa, /manage/info. Bearer tokens are protected with Data Protection and are only understood by the same app. They are not JWTs and there is no discovery, consent or client registration.
An identity provider speaks OIDC/SAML, issues tokens for many applications, runs MFA and conditional access, and handles federation. Note that Azure AD B2C stopped being offered to new customers in 2025; Microsoft Entra External ID is its replacement for customer identity. Duende IdentityServer needs a commercial licence for most companies; OpenIddict is open source.
AspNetUsers; decode the PasswordHash header bytes.PasswordHasherOptions.IterationCount, sign in, and observe the hash being rehashed.LockoutEnd; then remove lockoutOnFailure: true and repeat.MapIdentityApi and call /login with Postman; note the token isn't a JWT.PasswordHasher.HashPassword with BenchmarkDotNet and estimate CPU cost per sign-in.Identity with EF Core, stronger password and lockout settings, and the JSON endpoints for a SPA.
// Program.cs (.NET 10)
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDbContext<AppDbContext>(o =>
o.UseSqlServer(builder.Configuration.GetConnectionString("App")));
builder.Services.AddIdentityApiEndpoints<AppUser>(o =>
{
o.Password.RequiredLength = 12; // length beats composition rules
o.Password.RequireNonAlphanumeric = false;
o.Lockout.MaxFailedAccessAttempts = 5;
o.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(15);
o.SignIn.RequireConfirmedEmail = true;
o.User.RequireUniqueEmail = true;
})
.AddEntityFrameworkStores<AppDbContext>();
builder.Services.AddAuthorization();
var app = builder.Build();
app.UseAuthentication();
app.UseAuthorization();
app.MapGroup("/account").MapIdentityApi<AppUser>(); // /account/register, /account/login ...
app.MapGet("/me", (System.Security.Claims.ClaimsPrincipal u) => u.Identity!.Name).RequireAuthorization();
app.Run();
public sealed class AppUser : IdentityUser;
public sealed class AppDbContext(DbContextOptions<AppDbContext> options)
: IdentityDbContext<AppUser>(options);
PasswordSignInAsync with lockoutOnFailure: false (the template default in some places). Why it is wrong: failed attempts are never counted, so lockout never happens. Instead: pass true, and add rate limiting for credential stuffing.PasswordHasher (or Argon2 through a vetted library) and keep the work factor current.MapIdentityApi as an OAuth/OIDC server for other apps. Why it is wrong: its tokens are proprietary and only valid for the issuing app; there are no scopes or clients. Instead: use an identity provider when several apps or third parties need tokens.Password1!; NIST SP 800-63B favours length and breached-password checks. Instead: 12+ characters, a breached-password check and MFA.UserManager methods do it; call UpdateSecurityStampAsync in custom flows.Identity is a library; an identity provider is a service with an on-call rota. The real question is who should own credential risk. For a single app with its own users, Identity is cheap and solid, especially with passkeys in .NET 10. Once you have a second app, partners or staff accounts, owning passwords becomes a liability and a managed provider is cheaper than doing MFA, breach detection and audits yourself.
| Option | When it fits | Cost | When not to |
|---|---|---|---|
| ASP.NET Core Identity | One app, own users, full control | You run security features and incidents | SSO, third-party API access |
| Microsoft Entra ID | Workforce apps | Licences for advanced features (P1/P2) | Consumer sign-up |
| Entra External ID / Auth0 | Customer identity at scale | Per-MAU pricing | Tiny internal tools |
| Self-hosted Duende / OpenIddict | Need OIDC with full control or data residency | You operate a critical service | Small teams without security capacity |
Measure sign-in success rate, lockouts per day and MFA adoption; a lockout spike usually means credential stuffing.
After a successful login the app calls HttpContext.SignInAsync: the cookie handler serialises the ClaimsPrincipal into an authentication ticket, encrypts and signs it with Data Protection, and sends it as a cookie. On each request the handler decrypts the cookie and rebuilds HttpContext.User, with no database call.
HttpOnly (JavaScript can't read it), Secure (HTTPS only), SameSite=Lax by default (not sent on most cross-site requests).ExpireTimeSpan (default 14 days) with sliding expiration that reissues the cookie once half the window has passed; IsPersistent decides whether it survives closing the browser.The trade-off: a self-contained cookie is fast and stateless, but you can't revoke it without extra checks or a server-side ticket store.
OAuth 2.0 is a framework for delegated authorisation: a client gets an access token to call an API on a user's (or its own) behalf. It says nothing about who the user is. OpenID Connect is a thin identity layer on top that adds the ID token (a JWT about the user, for the client), the userinfo endpoint and discovery metadata.
code_verifier that it started the flow. Use it for web apps, SPAs and mobile.The trade-off: the redirect-based flows are more moving parts, but credentials never touch your app.
Last updated 23 Nov 2026.