📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

What does ASP.NET Core Identity give you out of the box: password hashing, lockout, two-factor, MapIdentityApi and the rest? When would you build on Identity, and when would you use an external identity provider such as Microsoft Entra ID instead?

ASP.NET Core Identity's features (user store, PasswordHasher, lockout, 2FA, passkeys, MapIdentityApi) and the decision between Identity and an external identity provider.

Junior Theory Beginner aspnet-core-identity authentication entra-id password-hashing security

🎯 Key points

  • Identity = membership system: users, passwords, roles, claims, tokens, EF Core store
  • PasswordHasher V3: PBKDF2-HMAC-SHA512, 100,000 iterations, random 128-bit salt; returns SuccessRehashNeeded to upgrade older hashes on sign-in
  • Lockout defaults (configurable): 5 failed attempts, 5 minutes; only counts when lockoutOnFailure: true
  • Two-factor (TOTP authenticator apps), recovery codes, email confirmation, security stamp
  • .NET 10 adds passkeys (WebAuthn) to Identity with schema version 3
  • MapIdentityApi: register/login/refresh endpoints for your own SPA or mobile app, with cookies or proprietary opaque bearer tokens; not an OIDC server
  • External IdP (Entra ID, Entra External ID, Auth0, Duende) for SSO, federation, conditional access and many apps

⏱ 30-second answer

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.

🗣 Full answer (senior)

How I would answer this in an interview

"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, SignInManager and RoleManager. The security pieces are the part people underestimate. Passwords are hashed with PasswordHasher, 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 pass lockoutOnFailure: 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. MapIdentityApi exposes JSON endpoints like /register, /login and /refresh so 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 MapIdentityApi as 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."


What Identity gives you

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

Identity or an external identity provider?

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

Production example

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.

🔍 What the interviewer is checking

Checks that the candidate knows what Identity really does for security and can make a sound build-vs-buy decision for identity.

Green flags

  • Names the hashing algorithm and lockout behaviour
  • Knows MapIdentityApi is not an OIDC server
  • Gives clear criteria for an external IdP (SSO, federation, conditional access)
  • Mentions passkeys or MFA

Red flags

  • Would hash passwords themselves
  • Thinks Identity is an authentication protocol
  • Builds a custom user database for staff who have Entra ID accounts

📚 Learn in depth

1. The architecture

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.

2. Password hash format

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.

3. Lockout and throttling

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.

4. MapIdentityApi

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.

5. External identity providers

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.

Try it yourself

  1. Create a project with Individual Accounts and inspect a row in AspNetUsers; decode the PasswordHash header bytes.
  2. Change PasswordHasherOptions.IterationCount, sign in, and observe the hash being rehashed.
  3. Try six wrong passwords and check LockoutEnd; then remove lockoutOnFailure: true and repeat.
  4. Add MapIdentityApi and call /login with Postman; note the token isn't a JWT.
  5. Benchmark PasswordHasher.HashPassword with BenchmarkDotNet and estimate CPU cost per sign-in.

💻 Code

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);

⚠ Common mistakes

  • Mistake: Calling 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.
  • Mistake: Writing your own password hashing with SHA-256. Why it is wrong: fast hashes are brute-forced at billions per second on GPUs. Instead: use PasswordHasher (or Argon2 through a vetted library) and keep the work factor current.
  • Mistake: Treating 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.
  • Mistake: Building a custom identity system for staff who already have Microsoft 365 accounts. Why it is wrong: it duplicates accounts, misses joiner/leaver processes and conditional access. Instead: sign staff in with Entra ID.
  • Mistake: Keeping the default composition rules but a short length. Why it is wrong: users pick Password1!; NIST SP 800-63B favours length and breached-password checks. Instead: 12+ characters, a breached-password check and MFA.
  • Mistake: Not updating the security stamp after a password or MFA change. Why it is wrong: existing sessions survive the change. Instead: UserManager methods do it; call UpdateSecurityStampAsync in custom flows.

🏛 Senior insight: trade-offs

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.

🔗 Follow-ups the interviewer may ask

  1. When: Candidate mentions Identity signing users in with a cookie Why: Checks how the Identity cookie and Data Protection work underneath
    How to answer

    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.

    • Flags: HttpOnly (JavaScript can't read it), Secure (HTTPS only), SameSite=Lax by default (not sent on most cross-site requests).
    • Expiry: 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.
    • Keys: every instance must share the Data Protection key ring, or cookies issued by one server can't be read by another.

    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.

  2. When: Candidate mentions an external identity provider Why: Checks they understand the OIDC flow that replaces local sign-in
    How to answer

    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.

    • Authorisation code + PKCE: the browser gets a one-time code, and the client swaps it for tokens, proving with a code_verifier that it started the flow. Use it for web apps, SPAs and mobile.
    • Client credentials: a service authenticates as itself; no user.
    • Implicit and password flows are deprecated (RFC 9700); OAuth 2.1, still an IETF draft in late 2026, makes that official.

    The trade-off: the redirect-based flows are more moving parts, but credentials never touch your app.

↩ Usually asked after

More in Authentication

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me