# Protect customer sign-in

> What protects a public customer sign-in today, how to tune lockout so it can't be turned against your customers, and what to add until bot protection arrives.

A customer sign-in is open to the whole internet, so it meets password guessing, credential stuffing and people
trying to lock others out. Every realm protects it from the first day: lockout stops guessing, the sign-in never says
which accounts exist, and passkeys leave nothing to guess or phish. Lockout locks the **account**, though, so on a
public realm you tune it for customers rather than staff. Bot challenges and checks per address are planned.

## Before you begin

- **Privilege:** `RealmOwner` in the customer realm to change sign-in settings; `RealmViewer` is enough to read them
  and the audit trail. See [Delegated administration](/platform/realms/delegated-administration/).
- **Where:** the dashboard (**Authentication → Settings**) or the API. [Call the API](/develop/api/) shows how to get
  `$CVYUH_SESSION`.

## How it works

| Protection | On by default | What it does |
|---|---|---|
| [Lockout](/workforce-identity/authentication/lockout/) | Yes | After repeated failures against one sign-in name, that account is refused for a while, even with the right answer |
| No account enumeration | Yes | A name the realm doesn't hold is answered and counted exactly as a real one, so no page reveals who has an account |
| [Passkeys](../passkeys-for-customers/) | Yes | Nothing to guess and nothing a fake site can capture |
| A second step | Yes | A password sign-in also asks for a code from an authenticator app |
| Bot challenges, checks per address, fake sign-up checks | Planned | See [What's next for customer sign-in](../whats-next/#bot-protection) |
| Breached-password checks | Planned | See [What's next for authentication](/workforce-identity/authentication/whats-next/#password-reuse-expiry-and-breached-passwords) |

### The lockout trade-off

Lockout counts failures against the **name typed**, not against where they come from. That is what stops a guesser
who targets one account, and it is also what lets anyone who knows a customer's sign-in name lock that customer out:
they type it with wrong answers until the account locks.

- **A lock stops every method.** A locked account is refused with a passkey too, not only with a password.
- **A lock ends on its own.** It lasts `lockoutDurationMinutes`, and an administrator can't end it sooner today.
- **Failed passkey attempts count** toward the lock, as wrong passwords and wrong codes do.

For staff, a long lock is a fair price. For customers, a lock is a customer who can't buy from you, so keep each one
short: a guesser still gets only a handful of tries per lock, and a customer who is locked out by someone else is back
in minutes.

## Set it up

As a realm administrator, set lockout for a customer realm: more tries before a lock, a short window and a short lock.

```sh
curl -X PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/authSettings/authSettings \
  -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
  -H "Content-Type: application/json" \
  -d '{ "lockoutThreshold": 10, "lockoutWindowMinutes": 15, "lockoutDurationMinutes": 15 }'
```

The realm answers `200`. Then:

1. **Move customers to passkeys.** A customer who signs in with a passkey has no password to guess or reuse; see
   [Passkey sign-in for customers](../passkeys-for-customers/).
2. **Keep the second step on** (`twoFactorMandatory: true`, the default for a new realm), so a guessed or reused
   password alone signs no one in.
3. **Protect your own sign-up form.** Accounts are made by your app's back end today (see
   [Create customer accounts](../../registration/create-customer-accounts/)), so put your own bot challenge and
   per-address limits on that form. That is where fake sign-ups are stopped until the realm does it.
4. **Watch for locks.** A rise in `ACCOUNT_LOCKED` records across many customers is an attack, not mistyping; see
   [Audit records](#audit-records).

Don't turn lockout off (`lockoutEnabled: false`, or a threshold, window or duration of `0`) on a public realm: that
leaves guessing unbounded.

## What customers see

- **A wrong password, code or passkey** is refused with the same message whether or not the account exists.
- **Close to a lock,** from the `lockoutWarnUser`-th failure (off by default), the page says how many attempts are
  left: "3 attempts left before your account is locked."
- **A locked account** is refused, without the page saying why. The customer can try again once the lock has passed.

## Limits and defaults

| Setting | Default | Range |
|---|---|---|
| `lockoutEnabled` | `true` | |
| `lockoutThreshold` | `5` failures | `0` turns lockout off |
| `lockoutWindowMinutes` | `300` | Up to the deployment's ceiling, a day unless changed; `0` turns lockout off |
| `lockoutDurationMinutes` | `30` | Up to the deployment's ceiling, a day unless changed; `0` turns lockout off |
| `lockoutWarnUser` | `0` (off) | Takes effect only below `lockoutThreshold` |
| `twoFactorMandatory` | `true` in a new realm | |

A setting past the ceiling is refused with `400`. Counting is per realm: a lock in one realm never reaches another.

## Troubleshooting

| Symptom | Cause | Fix |
|---|---|---|
| A customer can't sign in with the right password or passkey | Their account is locked, by their own mistakes or by someone typing their name | Read their trail for `ACCOUNT_LOCKED`. The lock ends after `lockoutDurationMinutes`; ask them to try again then |
| Many customers locked at once | Someone is typing many names with wrong answers | Shorten `lockoutDurationMinutes` so locks cost customers little, and move customers to passkeys |
| A customer locked again and again | Someone is aiming at that one account | Short locks keep them able to sign in between attempts. Change their sign-in name if they agree |
| Lockout seems never to trigger | Lockout is off, or the threshold, window or duration is `0` | Read `authSettings` and set all three above `0` |

## Audit records

Every sign-in and every lockout step is on the [audit trail](/audit-reports/audit-trail/what-is-recorded/), under
the customer's id:

| Event | When |
|---|---|
| `LOGIN_FAILED` | A sign-in failed, with each step's result and the address it came from |
| `AUTH_FAILURE_RECORDED` | A failure was counted toward a lock |
| `ACCOUNT_LOCKED` | The account locked |
| `LOCKOUT_CLEARED` | A successful sign-in cleared the count |
| `PATCHED` | A change to `authSettings`, before and after, in [Change history](/audit-reports/audit-trail/change-history/) |

[Look into a locked account](/audit-reports/guides/look-into-a-locked-account/) shows how to read them.

## Coming next

Bot challenges, checks that slow or block one address without locking the accounts it aims at, and fake sign-up
checks are on [What's next for customer sign-in](../whats-next/#bot-protection).

## Related

- [Lockout](/workforce-identity/authentication/lockout/): every lockout setting.
- [Passkey sign-in for customers](../passkeys-for-customers/): the sign-in with nothing to guess.
- [Look into a locked account](/audit-reports/guides/look-into-a-locked-account/): read the failures behind a lock.
