Files

4.4 KiB

Code summary - U3 password-reset

What was built

Core

  • Identity gets the default token providers (stateless data-protection reset token, single use through the security stamp). PasswordResetSettings (section Identity:PasswordReset: TokenLifetimeMinutes default 60, range 5..1440; CooldownMinutes default 5, range 1..60), validated at start-up; the reset link lifetime is the data-protection token lifetime.
  • IPasswordResetService:
    • RequestAsync(email): only when mail is on and the cooldown allows; unknown, deactivated and blank addresses do nothing; sends the reset mail. It writes nothing else: no password, security stamp, access token or refresh token is touched. Never throws.
    • ResetAsync(userId, token, newPassword): UserManager.ResetPasswordAsync; a bad, expired, used or foreign token, an unknown or deactivated user are one generic InvalidLink; a password-policy failure (checked after the token, so only a link holder sees it) is PasswordRejected and does not use up the link. Only a completed reset revokes every refresh token of the account; earlier access tokens end through the changed security stamp (D2).
  • ResetCooldown (in memory, TimeProvider-driven): one mail per address per window, unknown addresses included, bounded memory (purge, hard cap 10,000, refuse new addresses when full).
  • IPasswordResetDispatcher / BackgroundPasswordResetDispatcher: the anonymous endpoint answers first and the request is handled afterwards in its own scope, so the response time does not tell whether the address exists and a slow SMTP server cannot hold the request (a deliberate difference from the in-request sending of administrator-triggered mails).
  • IIdentityMailService.SendPasswordResetAsync: link App:PublicBaseUrl/admin/reset-password?uid=<user id>&token=<token> (user id, no e-mail address in a URL), recipient's language, lifetime stated in the mail.

Identity module (AuthController): POST auth/forgot-password (anonymous, login rate limiter): 404 on a site without mail, 400 for a malformed address, otherwise always the same 202 body. POST auth/reset-password (anonymous, login rate limiter): input bounds (token 2048, password 128, non-empty user id), 200, or 400 with invalid_link / password_rejected.

Frontend: /forgot-password (neutral "if this address belongs to an account..." message; 404 explained), /reset-password?uid&token (same password rules as everywhere, success, one generic "link invalid or expired" page with "request a new link", a rejected password keeps the form), "Wachtwoord vergeten?" on the login page only when emailEnabled, nl/en strings.

Tests

  • Core.Tests (real Identity, real data-protection tokens, real bearer check on a TestServer): a request leaves password hash, security stamp, refresh tokens, the earlier access token and the old password all working (Bryan's rule); a completed reset sets the new password, ends the earlier access token (401), revokes the refresh token, no active refresh tokens remain, the old password fails; the link works once; an expired link is refused and the password stays; another user's token, garbage and an unknown user are refused; a weak password is reported without using up the link; unknown, deactivated and blank addresses send nothing and do not throw; a deactivated account cannot complete a reset; a site without mail does nothing; one mail per address per window (case-insensitive) then works again; the cooldown also applies to unknown addresses; cooldown memory bound; property-based: for any request sequence two accepted requests for one address are never closer than the window (PBT-03); settings ranges; DI wiring and start-up validation; dispatcher returns at once and handles in the background, a failing request never surfaces; reset mail link carries the user id and no address.
  • Identity.Tests 126: both endpoints anonymous and under the login limiter, same 202 for any well-formed address, malformed addresses rejected without dispatching, 404 without mail, outcome mapping, bounds.
  • Frontend 355: login link only with mail, validation, neutral sent message, 404, missing link, rules, token/uid sent, generic invalid page, rejected password keeps the form.

Behaviour change for SlpSoftware (and every host)

Identity registration now includes the default token providers (inert unless a reset is requested); the two endpoints answer 404 while mail is off; nothing else changes without mail.