Writing good logs
NIST defines a log as a record of the events in an organisation's systems. Each event should say when, where, who and what. You cannot detect what you never wrote down, so logging comes first.
Ana mistypes her password once, then gets in. The sign-in service writes one line per attempt, a small JSON (plain text data) record: time, user, address and event. OWASP names a failure authn_login_fail. Failures matter most.
A common mistake is logging the whole sign-in request, password included. Then anyone who reads the logs can sign in as Ana. OWASP says never log passwords, session IDs, access tokens or keys. Log the outcome instead.
Each line is copied at once to a central log store. An intruder on the server then cannot quietly erase it, and lines from many systems can be compared. Clocks are synced, so their times line up.
Detecting an attack
Now someone at 203.0.113.7 tries password after password for ana. Each guess fails, and each failure becomes a line: five in 40 seconds, from an address Ana never uses. The evidence is in the log.
A detection rule is code that watches the log. This one reads each line, turns the JSON into a dictionary, and keeps only failures. Each user gets their own list, q, of recent failure times. Ana's typo is there.
When the failure at t=100 arrives, it joins q. The while loop then drops times 60 seconds old or more, so the typo at t=20 falls out. The rule only counts recent failures, not old mistakes.
More failures arrive at 112, 121, 133, 140. None is a minute old yet, so q grows to five. len(q) equals LIMIT, and the rule prints an alert naming the user and the address.
From alert to response
The alert reaches an analyst, who triages it: is it real? They compare it with other logs. Ana signs in from 198.51.100.20, not 203.0.113.7, and nobody there knows the password. It is real: declare an incident.
Rules need tuning. A limit too low raises false alarms for every typo, and tired analysts start ignoring alerts. Too high, and real attacks slip by. Slow guessing, or one password tried on many accounts, needs other rules.
The analyst responds: the service blocks the address, checks that no guess worked, and turns on MFA (a second proof, like a phone code) for Ana. NIST's incident guide links detect, respond and recover. The response is logged too, and the rule is reviewed.
What happens
;; step 1/11 · events log a record of events (NIST SP 800-92) when the time it happened where which app or server who which user, from which address what the event and its outcome
Real logs carry a full date and time, usually in UTC in ISO 8601 form (2026-11-06T09:00:20Z), and OWASP asks for both the event time and the logging time. The figure uses seconds since the log began so the window maths stays easy to read. Five failures in 60 seconds is an example threshold, not a standard. Each organisation tunes its own numbers from its normal traffic. Services should also slow down or limit repeated failed sign-ins on their own, not only alert.