Passwordless login by email replaces a memorised password with proof that you control a mailbox. The user enters an address, receives a message containing either a link that signs them in (a magic link) or a short code to type, and gets in. Done well, it removes password reuse, resets and a large class of phishing. Done carelessly, it moves the whole security of the account into one fragile place: the delivery of an email, which can be slow, filtered, delayed, forwarded or pre-fetched by security software. A sign-in email that arrives late or never is a locked-out customer, and a link that works for anyone who holds it is an open door. This guide covers how the flows work, what makes them secure, how scanners and clients interfere, what deliverability they need and a checklist for building them. It builds on password reset emails, OTP emails and rate limits and backoff.
The two flows compared
| Property | Magic link | One-time code |
|---|---|---|
| User action | Open the email and tap the link | Read the code and type it into the page that requested it |
| Device | May open on a different device or browser than the one that asked | Entered in the original session, so the request and completion are bound together |
| Security strengths | Long random token, hard to guess; no typing | Short-lived; attacker needs both the session and the code |
| Weaknesses | Link scanners may open and consume it; forwarding or sharing gives access; opens in the wrong browser (in-app browser) | Easy to phish by asking the user to read the code aloud; guessing risk if the code is short and attempts are not limited |
| Mobile experience | Excellent when the mail app opens the right browser | Copy and paste or autofill from a notification or the one-time-code hint |
| Accessibility | Link must be keyboard reachable and clear | Screen readers can read short codes, but long ones are tiring |
| Deliverability sensitivity | Both rely entirely on prompt delivery | Same |
Security rules
- Use high-entropy tokens. A link token should have at least 128 bits of randomness from a cryptographic generator, stored hashed on the server like a password.
- Make them single use. Invalidate the token the moment it is used, and when a new request replaces the old one.
- Keep expiry short. Ten to fifteen minutes is common for sign-in links and codes. Longer lifetimes increase exposure, shorter lifetimes increase lockouts when mail is delayed.
- Bind to the requesting session. Store a nonce in the browser that asked for the link and require it when the link is opened. If the link opens on another device, ask the user to confirm on the original device or fall back to entering a code.
- Limit attempts. For codes, allow a handful of tries before invalidating, and rate-limit requests per address, per account and per IP. See rate shaping.
- Use six or more digits (or letters and digits) for codes, and compare in constant time.
- Never put the token in places that leak it. Avoid logging full URLs, put the token in the path or fragment as appropriate, set a strict referrer policy and avoid third-party scripts on the landing page.
- Show context in the email. Include the time, approximate location and device of the request, and a clear "If this was not you, ignore this message".
- Protect the sign-up and enumeration paths. Respond with the same message whether or not the address has an account, if your product allows it, to avoid revealing who is registered.
- Log and alert on unusual patterns such as many requests for different addresses from one source. See bot protection.
Link scanners and prefetchers
Corporate security gateways, antivirus tools and some mail clients fetch links in incoming mail to check them. A magic link that signs in on any GET request is consumed by the scanner before the person clicks, and the user sees "link expired". Defences:
- Make the link open a confirmation page that requires a deliberate action (a button that sends a POST) before the token is redeemed. Scanners follow links but do not click buttons.
- Redeem only on a POST request with a CSRF token, never on a plain GET.
- Allow a short grace period for repeated redemption from the same browser session while still rejecting other sessions.
- Detect common scanner user agents and IP ranges as a hint, not as a security control.
- Offer the one-time code as a fallback in the same email, so users in strict environments can still sign in.
- Tell users what to do when a link is "expired": request a new one and use the code.
Deliverability is part of authentication
If sign-in depends on email, the sending path is part of your login system. Treat it with the same care as a database.
| Requirement | Practice |
|---|---|
| Separate stream | Send authentication mail from a dedicated subdomain or IP pool, apart from marketing. See IP pools |
| Full authentication | Pass SPF, DKIM and DMARC aligned to your domain. See envelope From |
| Instant delivery | Send immediately, with priority queues and short retry windows. See retry schedules |
| Minimal, stable content | Short text, one link or code, consistent subject and From name; avoid images and heavy HTML |
| Plain-text part | Include one for clients and filters. See plain text |
| Links on your domain | Use your own branded link domain, not a shortener or a shared tracker; disable click tracking on authentication links |
| No unsubscribe footer needed for pure transactional mail | Follow your legal advice; do not mix promotions into the message |
| Monitoring | Track delivery time (p50, p95), bounces and complaints for this stream and alert on delays. See SMTP monitoring |
| Fallbacks | Offer another sign-in method (password, passkey, SSO) so a mail outage does not lock users out |
User experience details
- After the request, show a clear waiting page: where the mail was sent, how long it can take, a resend button with a cooldown and a "change email" option. See catching email typos.
- Put the code in the subject or first line so it appears in notifications, and use the standard one-time-code format that lets phones offer autofill.
- Make the link open in the default browser where the user started, if possible; in-app browsers lose the session binding.
- Handle expired and used links with a helpful message and a one-click way to request a new one.
- Do not email the code to an address the user just typed without a typo check.
- Provide a clear path for people who cannot receive email at all (support, alternative method).
Build checklist
| Item | Done when |
|---|---|
| Token generation | Cryptographically random, stored hashed, single use, expires in minutes |
| Redemption | Confirmation step via POST, scanner-safe |
| Session binding | Nonce or code ties the redemption to the original browser |
| Rate limits | Per address, account and IP; code attempt limits |
| Email path | Dedicated stream, aligned authentication, plain-text part, no tracking |
| Observability | Delivery latency, success rate and abuse metrics on a dashboard |
| Fallback | Another sign-in method is available |
| Privacy | No sensitive data in the email; tokens not written to logs |
| Testing | Tested with strict security gateways, in-app browsers, slow delivery and forwarded messages |
Passwordless email can be both safer and friendlier than passwords, provided the email path is treated as part of the security design. Use random, short-lived, single-use tokens, bind them to the requester, protect against scanners, deliver them quickly from an authenticated, dedicated stream and give users a way in when email is slow.
Send authentication mail reliably Dedicated, authenticated sending for transactional messages.
References and further reading
Frequently asked questions
What is a magic link?
A single-use, time-limited URL emailed to the user that signs them in without a password.
Why do magic links sometimes say expired?
Security scanners may fetch the link before the user clicks, consuming the token; use a confirmation page with a POST step.
How long should a login link or code last?
Typically ten to fifteen minutes, balancing security against delays in email delivery.
Should I use a code or a link?
Codes bind the request to the original session and suit strict environments; links are convenient on mobile. Offering both in one email is common.
What if email delivery is delayed?
Provide a resend option with a cooldown and an alternative sign-in method so users are not locked out.