# Passwordless login

> Let customers sign in with their mobile number and a code instead of a password.

1. The customer types their number. Your server normalizes it and looks up the account.
2. **Send the code whether or not an account exists**, or answer the same way in both cases, so the form doesn't reveal which numbers are registered. (Sending only to known numbers saves money; then show the same "If this number has an account, we sent a code" message either way.)
3. Send with `purpose: "login"` and keep the `id` and the account id in the session.
4. On `valid: true`, start the session for **that** account. Rotate the session id when signing in.

## Security

- Never accept a "verified" flag, a phone number or an account id from the browser at step 4: use only what your server stored at step 3.
- OTP.ps allows 5 tries per code and limits codes per number (per number: one code every 30 seconds, 5 an hour and 10 a day; per account: 120 codes a minute (test and live keys are counted separately)). Also limit login attempts per account and per IP on your side.
- Codes expire (5 minutes by default). Keep the login session short-lived until the code is checked.
- A text message is a reasonable second factor for a shop, but not for high-value accounts on its own: offer something stronger for admins.
