Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
6.0 KiB
admin-login-security Specification
Purpose
Protect admin sign-in against password guessing: record every admin sign-in, sign-out, unlock and own password change, lock a username after repeated failures, and let authorised admins read the history, unlock staff and edit the lockout and password-rule settings.
Requirements
Requirement: Login history
The system SHALL record every admin sign-in attempt, sign-out, unlock and own password change, with the time, trimmed username, event, client IP, user agent and, for a known username, the user's company. Events: LOGIN_SUCCESS, LOGIN_FAIL, LOGIN_LOCKED, LOGOUT, UNLOCK_RESET, PASSWORD_CHANGED. Recording SHALL be best-effort and MUST NOT change the sign-in answer. A blank username or password SHALL NOT be recorded.
Scenario: Successful sign-in is recorded
- WHEN
sales1signs in with the right password - THEN a
LOGIN_SUCCESSrecord forsales1is saved with the time, client IP and user agent
Scenario: Failed sign-in is recorded
- WHEN someone signs in as
sales1with a wrong password - THEN a
LOGIN_FAILrecord forsales1is saved
Scenario: Unknown username is recorded
- WHEN someone signs in as
nobody1, which matches no user - THEN a
LOGIN_FAILrecord fornobody1is saved with no company
Scenario: Sign-out is recorded
- WHEN
sales1signs out - THEN a
LOGOUTrecord forsales1is saved
Scenario: History write failure does not block sign-in
- GIVEN the history cannot be written
- WHEN
sales1signs in with the right password - THEN the sign-in succeeds
- AND the write failure is logged
Requirement: Lockout after repeated failures
The system SHALL lock a username when lockout is on and its LOGIN_FAIL records reach the configured maximum, counting only records inside the configured period and after its latest LOGIN_SUCCESS, UNLOCK_RESET or PASSWORD_CHANGED. The maximum, period, unit and on/off switch SHALL come from settings. Failures SHALL count for unknown usernames too, so a lock does not reveal whether an account exists. The lock SHALL end once the counted failures leave the period.
Scenario: Maximum reached locks the username
- GIVEN lockout is on with a maximum of 5 in 15 minutes
- WHEN
sales1fails to sign in 5 times within 15 minutes - THEN
sales1is locked
Scenario: Old failures do not count
- GIVEN lockout is on with a maximum of 5 in 15 minutes
- WHEN
sales1has 4 failures within the last 15 minutes and 3 older ones - THEN
sales1is not locked
Scenario: A success resets the count
- WHEN
sales1fails 4 times, signs in successfully, then fails 4 more times within 15 minutes - THEN
sales1is not locked
Scenario: Lockout switched off
- GIVEN lockout is off
- WHEN
sales1fails 10 times within 15 minutes - THEN
sales1is not locked
Requirement: Locked username is refused
The system SHALL refuse sign-in for a locked username before checking the password, with the code ACCOUNT_LOCKED and a message telling the user to try later or ask an administrator, and SHALL record LOGIN_LOCKED. When the lock state cannot be read because of an infrastructure error, sign-in SHALL proceed to the normal password check.
Scenario: Right password while locked
- GIVEN
sales1is locked - WHEN
sales1signs in with the right password - THEN sign-in is refused with
ACCOUNT_LOCKED - AND no session is issued
- AND a
LOGIN_LOCKEDrecord is saved
Scenario: Lock check unavailable
- GIVEN the lock state cannot be read
- WHEN
sales1signs in with the right password - THEN the sign-in succeeds
Scenario: Portal shows the locked message
- WHEN sign-in is refused with
ACCOUNT_LOCKED - THEN the login page shows the locked message instead of "Invalid username or password"
Requirement: Unlock
The system SHALL let an admin with BO_LOGIN_SECURITY list the usernames that are locked now, with their failure count, last failure time and when the lock ends, and SHALL let that admin unlock one. Unlocking SHALL save an UNLOCK_RESET record naming the admin who unlocked.
Scenario: Unlock a locked username
- GIVEN
sales1is locked - WHEN an admin with
BO_LOGIN_SECURITYunlockssales1 - THEN
sales1no longer appears in the locked list - AND
sales1can sign in with the right password - AND an
UNLOCK_RESETrecord forsales1names the admin
Requirement: Login history screen
The system SHALL let an admin with BO_LOGIN_SECURITY read the login history, newest first and paged, filtered by username, event and date range.
Scenario: Filter by event
- WHEN an admin filters the history by event
LOGIN_FAIL - THEN only
LOGIN_FAILrecords are listed, newest first
Scenario: Without the module
- WHEN an admin without
BO_LOGIN_SECURITYcalls the login-security API - THEN the request is refused with 403
Requirement: Lockout and password-rule settings
The system SHALL let an admin with BO_LOGIN_SECURITY read and change the lockout settings (on/off, maximum attempts, period, time unit) and the admin password rules (each rule's on/off status and value). The system SHALL reject a maximum below 1 or above 1000, a period below 1 or above 10000, and a time unit other than S, M, H or D. Password rules SHALL only be edited, never added or removed. Every change SHALL write a log line naming the admin.
Scenario: Change the lockout settings
- WHEN an admin sets the maximum to 3 and the period to 30 minutes
- THEN the next lock decision uses 3 attempts in 30 minutes
Scenario: Invalid setting
- WHEN an admin sets the maximum to 0
- THEN the change is refused with a validation error and the settings stay as they were
Scenario: Change a password rule
- WHEN an admin sets the minimum length rule to 10
- THEN a new password of 9 characters is refused by every admin password check