U3 password-reset (backend): wachtwoord vergeten en opnieuw instellen

POST auth/forgot-password antwoordt altijd hetzelfde (202) en handelt de mail na het antwoord
af; POST auth/reset-password zet een nieuw wachtwoord met de link uit de mail. Alleen een
voltooide reset trekt alle refresh tokens in (en beeindigt eerdere access tokens via de
security stamp); het aanvragen raakt niets. Link eenmalig en tijdsbeperkt (standaard 60 minuten),
cooldown van 5 minuten per adres in het geheugen, beide endpoints onder de login-limiter.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-08 19:21:29 +01:00
co-authored by Claude Sonnet 5.5
parent 3cba2facb3
commit c8e23826c3
11 changed files with 901 additions and 9 deletions
@@ -38,6 +38,7 @@ public class IdentityMailServiceTests
Options.Create(new EmailOptions { LogoUrl = logo, BrandColor = "#5f6a58", Smtp = { Host = smtpHost } }),
Options.Create(new AppMailOptions { DefaultLanguage = defaultLanguage, PublicBaseUrl = "https://test.andreaslop.nl/" }),
Options.Create(new InvitationSettings { ExpiryHours = hours }),
Options.Create(new SlpModularCms.Core.Identity.Services.PasswordResetSettings()),
NullLogger<IdentityMailService>.Instance);
[Fact]
@@ -163,4 +164,20 @@ public class IdentityMailServiceTests
[InlineData("https://t.nl", "login", "https://t.nl/admin/login")]
public void BuildLink_PutsTheAdminBasePathBetweenSiteAndPath(string baseUrl, string path, string expected) =>
IdentityMailService.BuildLink(baseUrl, path).Should().Be(expected);
[Fact]
public async Task PasswordReset_LinksToTheResetPage_WithTheUserIdNotTheAddress_AndTheLifetime()
{
var user = new ApplicationUser { Id = Guid.Parse("11111111-2222-3333-4444-555555555555"), Email = "jan@example.org", DisplayName = "Jan", PreferredLanguage = "en" };
await Service().SendPasswordResetAsync(user, "to/ken+1=");
var mail = _sender.Sent.Single();
mail.Subject.Should().StartWith("Reset your password");
mail.HtmlBody.Should().Contain("https://test.andreaslop.nl/admin/reset-password?uid=11111111-2222-3333-4444-555555555555&amp;token=to%2Fken%2B1%3D");
mail.TextBody.Should().Contain("https://test.andreaslop.nl/admin/reset-password?uid=11111111-2222-3333-4444-555555555555&token=to%2Fken%2B1%3D")
.And.Contain("1 hour").And.Contain("unchanged");
// Nothing in the link identifies the account by its address.
mail.TextBody!.Split("https://", 2)[1].Split('\n', 2)[0].Should().NotContain("jan@example.org").And.NotContain("%40");
}
}