Skip to content

Frontend API login: honour the login lockout - #1101

Merged
KrzysztofPajak merged 3 commits into
developfrom
fix/tokenweb-login-lockout
Nov 23, 2026
Merged

KrzysztofPajak merged 3 commits into
developfrom
fix/tokenweb-login-lockout

Conversation

@KrzysztofPajak

@KrzysztofPajak KrzysztofPajak commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

The frontend API token login (/TokenWeb/Login, LoginWebValidator) checked the password through LoginCustomer only. Unlike the storefront LoginValidator it did not look at CannotLoginUntilDateUtc and did not raise CustomerLoginFailedEvent. With lockout turned on (FailedPasswordAllowedAttempts > 0), a locked-out account still got a token there, and wrong passwords tried there were never counted.

Changes

  • LoginWebValidator:
    • refuses a locked-out or deleted account before the password is checked
    • raises CustomerLoginFailedEvent when LoginCustomer reports a wrong password, so these attempts count towards the lockout
    • a password that is not base64 fails validation instead of throwing a FormatException (500)

Notes

  • Lockout itself stays off by default (FailedPasswordAllowedAttempts = 0); whether to turn it on for new installations is a separate decision.

Tests

  • LoginWebValidatorTests: locked-out account fails without a password check, wrong password raises the event, non-base64 password fails.
  • Grand.Module.Api.Tests (113) pass.

Review follow-up

  • A successful API login now clears FailedLoginAttempts and CannotLoginUntilDateUtc and stamps LastLoginDateUtc (UpdateCustomerLastLoginDate), as the login page does, so occasional typos no longer add up to a lockout. CustomerLoggedInEvent is not published: its cart merge needs a guest the API login does not have.
  • With UsernamesEnabled, LoginCustomer looks the customer up by username; the validator now passes the username of the customer it found by e-mail instead of the e-mail, which found nobody and failed with an error.
  • LoginWebValidatorTests: both cases. Grand.Module.Api.Tests (115) pass.

The frontend API token login checked the password through LoginCustomer only. It did not look at CannotLoginUntilDateUtc and did not report a wrong password, so with lockout turned on a locked-out account still signed in there and wrong passwords there were never counted.

The validator now refuses a locked-out or deleted account before the password check, raises CustomerLoginFailedEvent on a wrong password as the storefront login does, and treats a password that is not base64 as a failed login instead of an error.
Copilot AI balanced review requested due to automatic review settings November 23, 2026 05:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

support and others added 2 commits November 23, 2026 07:22
…username when usernames are on

Wrong passwords on the API login now count towards the lockout, but a successful API login never cleared them, so an app user who mistyped now and then was locked out in the end. A successful login now resets the failed attempts and stamps the last login date, as the login page does, without the cart merge the login page's event also runs.

With usernames enabled, LoginCustomer looks the customer up by username, so the e-mail the API passed found nobody and the login failed with an error. The validator now passes the username of the customer it found by e-mail.
@KrzysztofPajak
KrzysztofPajak merged commit f619321 into develop Nov 23, 2026
9 checks passed
@KrzysztofPajak
KrzysztofPajak deleted the fix/tokenweb-login-lockout branch November 25, 2026 09:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants