Email sign-in links (one-time "magic links")
authenticationmagic-linkpasswordlessemailtokense2etldr
An emailed sign-in link lets someone log in without typing a password: they ask for a link, open their email, and tap it. It is a good fit for people who keep forgetting passwords. The safe version is one-time, short-lived and emailed on request; a permanent login URL is not. TLDR shipped this in v1.64.0 (2026-11), and this article is the design that came out of it.
Why not a permanent link
The request was first "a permanent login link he can always click". A link that never expires is a bearer password sitting in an email, chat or browser history forever: anyone who sees it is the user, and there is no way to notice. It also leaves end-to-end encrypted data locked, because the keys are wrapped under the password (below). One-time links keep the convenience and drop both problems.
Requesting a link
POST /user_actions/login_link {username} (username or email):
- Always answer the same way (201), whether or not the account exists, so the endpoint can't be used to check which usernames or emails are registered.
- Skip unverified or deactivated accounts silently.
- Rate limit per account (3 links per 15 minutes), so nobody can flood a user's inbox.
- Generate 32 random bytes (64 hex characters), store only the SHA-256 hash of the token (a database leak then reveals no usable links), and email https://<site>/login/link/<token>.
Redeeming it
POST /user_actions/login_link_redeem {token}:
- Claim the token atomically: UPDATE login_link SET used_date = NOW() WHERE token_hash = ? AND used_date IS NULL AND created_date > NOW() - INTERVAL 15 MINUTE, and succeed only if one row changed. Two simultaneous clicks can't both win.
- Single use, 15-minute lifetime. On success, invalidate the account's other outstanding links.
- Return exactly what a password login returns (JWT, user, key backup) from a shared helper, so the client has one sign-in path.
- Anything else is a 401 with a reason (link_invalid); don't say whether the link was expired, used or never existed.
- Prune rows older than a day on each request; no cron needed.
- The table keys the username with ON UPDATE CASCADE ON DELETE CASCADE, so renaming or deleting a user can't leave orphans.
Tap to sign in, don't redeem on load
Mail providers and corporate filters open links to scan them, and some run JavaScript. If the page redeems the token as soon as it loads, the scanner burns the one-time link before the person ever sees it. The link should open a page with a "Sign in" button, and only the tap redeems. The page should also sign out any current session first, so the link never mixes two accounts on one device.
End-to-end encrypted data needs the password
If the app has E2E messaging whose private keys are backed up wrapped under the user's password (E2E key management that never loses a key (keyring, backup, re-wrap)), a passwordless sign-in can authenticate the user but cannot unwrap their keys. The dangerous default is the code path "no cached key, no password, so generate a fresh key pair", which would later publish a new public key over the real one and strand every old message. - Before generating keys without a password, ask the server whether the user already has a published key. If one exists, or the check fails, mark messaging as locked on this device and stop. - Tell the user what to do: "Messages are locked on this device. Sign in with your password to read them." - This guard protects every passwordless start, including restarts after the app's storage was wiped, not just link sign-ins. - A device that already holds the raw key (the usual case for a returning user) keeps working.
Testing
Check: unknown user still gets 201; bad, reused and expired tokens give 401; the redeem response carries a JWT but no password hash; the fourth request inside the window sends nothing; redeeming one link kills the others. A mailbox that doesn't exist (an AI or test account) defers the mail, which is expected.
See also
- "Anyone with the link" share links (capability URLs)
- Migrating legacy password hashes to bcrypt on login
- API authorization from the verified identity (and the holes it closes)
- Sending mail from PHP with Postfix, SPF, DKIM and DMARC