# Look into a locked account

> When a user is locked out, read the failed sign-ins and the lockout behind it, with why each attempt failed and when, to tell mistyping from someone else trying.

`maya` calls the help desk: she can't sign in. Before anything is reset, you want to know whether she mistyped her
password a few times or someone else has been trying it. Her trail holds every failed sign-in against her account,
with why each one failed and when, and the lockout records show when the account was locked.

**Before you start:** you hold `READ` on the realm (`RealmViewer` is enough), and are signed in with your session in
`$CVYUH_SESSION` ([Call the API](/develop/api/) shows how).

## What the user sees

After repeated wrong passwords or codes, `maya`'s sign-in is refused even with the right password, until the lock
ends. If your realm warns users, she was told how many attempts were left before it locked. See
[Lockout](/workforce-identity/authentication/lockout/).

## Read the attempts

<Steps>

1. Look up her `id`:

   ```sh
   curl https://foobar.cvyuh.com/api/v0/am/objects/v1/user/maya \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"
   ```

2. Read her trail, newest first:

   ```sh
   curl "https://foobar.cvyuh.com/api/v0/am/audit/v1/trail?person=<maya's id>&pageSize=100" \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"
   ```

3. In `events.data`, find the `LOGIN_FAILED` records. Each has its `eventTime`, the name as it was typed in
   `context.name`, and why it failed in `context.code`:

   | `context.code` | Means |
   |---|---|
   | `AUTH_INVALID_PASSWORD`, `AUTH_INVALID_PASSWORD_WARNED` | A wrong password or code |
   | `AUTH_MAX_ATTEMPTS` | The attempt that locked the account |
   | `AUTH_USER_LOCKED` | An attempt while it was locked |

4. Read the lockout records. They are kept under the name she signs in with, in lower case, rather than her id:

   ```sh
   curl "https://foobar.cvyuh.com/api/v0/am/audit/v1/trail?person=maya&pageSize=100" \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"
   ```

   `AUTH_FAILURE_RECORDED` is each failure counted, `ACCOUNT_LOCKED` the moment the account locked, and
   `LOCKOUT_CLEARED` the count cleared by a successful sign-in.

5. Compare the times. A few failures close together, then a successful `LOGIN`, read as mistyping. Many failures
   spread over hours, attempts that keep coming while the account is locked (`AUTH_USER_LOCKED`), or the name typed in
   forms she doesn't use, read as someone else trying her password.

</Steps>

<Aside type="note" title="Where the attempts came from">
  A failed sign-in's record doesn't carry the address it came from today. Her successful `LOGIN` records do, in each
  step's `info.ipAddress`, so you can see where she usually signs in from.
</Aside>

## Check it worked

Once she signs in again, a `LOGIN` record with `"result": "SUCCESSFUL"` is on her trail, and a `LOCKOUT_CLEARED`
record on the name read. A lock that simply runs out writes no record of its own.

## Undo it

Nothing to undo: reading the trail changes nothing. If someone else has been trying her password, have her change it
once she is back in, and consider a second sign-in step for her.

## Troubleshooting

| Symptom | Cause | Fix |
|---|---|---|
| No `LOGIN_FAILED` records under her id | The name typed didn't match her account | Read by the name typed, in lower case, as in step 4 |
| No `ACCOUNT_LOCKED` on her trail | Lockout records are kept under the name, not her id | Step 4 |
| The step 4 read shows attempts for `Maya` and `MAYA` together | Names are counted in lower case | Expected: they are one account's attempts |
| `403` | You don't hold `READ` on the realm | Ask for `RealmViewer` |

## Related

- [Lockout](/workforce-identity/authentication/lockout/): what locks an account, and the settings.
- [Record fields and examples](/audit-reports/audit-trail/record-fields/): a failed sign-in's record, field by field.
- [Read a user's or agent's trail](/audit-reports/audit-trail/read-a-trail/): paging and who may read.
