Verification code email template

A 6-digit code to confirm an address or sign in. Free to copy, with the best practices that make it easy to type and hard to guess.

What your users receive

Your Acme verification codeThe code expires in 10 minutes.

Copy the code

The email itself. Paste it where your app builds the message, then replace Acme with your product name, {{email}} with the address and {{code}} with the code your app generates.

Subject: Your Acme verification code
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="color-scheme" content="light">
  <meta name="supported-color-schemes" content="light">
  <title>Your Acme verification code</title>
</head>
<body style="margin:0;padding:0;background-color:#f4f4f5;">
  <div style="display:none;max-height:0;overflow:hidden;opacity:0;mso-hide:all;">The code expires in 10 minutes.&#8199;&#65279;&#847;&#8199;&#65279;&#847;&#8199;&#65279;&#847;&#8199;&#65279;&#847;</div>
  <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="background-color:#f4f4f5;">
    <tr>
      <td align="center" style="padding:32px 16px;">
        <table role="presentation" width="100%" cellpadding="0" cellspacing="0" border="0" style="max-width:480px;background-color:#ffffff;border:1px solid #e4e4e7;border-radius:8px;">
          <tr>
            <td style="padding:32px;font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,Helvetica,Arial,sans-serif;color:#18181b;">
              <h1 style="margin:0;font-size:22px;line-height:28px;font-weight:700;">Confirm your email address</h1>
              <p style="margin:12px 0 0;font-size:15px;line-height:22px;">Enter this code in Acme to confirm {{email}} and finish creating your account:</p>
              <p style="margin:24px 0 0;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:30px;line-height:38px;font-weight:700;letter-spacing:8px;">{{code}}</p>
              <p style="margin:24px 0 0;font-size:13px;line-height:20px;color:#52525b;">The code expires in 10 minutes.</p>
              <p style="margin:12px 0 0;font-size:13px;line-height:20px;color:#52525b;">Never share this code. Acme will never ask you for it, by phone, email or chat.</p>
              <p style="margin:12px 0 0;font-size:13px;line-height:20px;color:#52525b;">If you didn't create an account on Acme, ignore this email.</p>
            </td>
          </tr>
        </table>
      </td>
    </tr>
  </table>
</body>
</html>

What to put in the email

A code email is read for a few seconds, just long enough to copy six digits into a page that is still open. Everything else in it is there for the rare reader who didn't expect it.

  1. Make the code the first thing they see

    Put the code right under the heading, after one sentence. On a phone, people switch to the inbox, glance at the email and switch back: the code should be readable without scrolling.

    Confirm your email address

    Enter this code in Acme to confirm ada@example.com and finish creating your account:

    739214

    The code expires in 10 minutes.

    Never share this code. Acme will never ask you for it, by phone, email or chat.

    If you didn't create an account on Acme, ignore this email.

  2. Make the code easy to read and copy

    Show it large, in a font where every digit has the same width. Space the digits with the font's letter spacing, not with a space character: a double tap on a phone selects one word, so a code written "739 214" gets copied half at a time.

    Digits avoid the confusion between 0 and O, or 1, l and I. If your codes need letters, leave out those that look alike.

    Split with a space
    739 214A double tap selects half the code
    Spaced by the font
    739214A double tap selects the whole code
  3. Keep the code out of the subject and preview text

    The subject and the preview text show on lock screens and in notifications, where anyone near the phone can read them. Name the product and the purpose in the subject, and keep the code inside the email.

    Avoid
    10:04
    Acme
    739214 is your Acme code
    Do
    10:04
    Acme
    Your Acme verification codeThe code expires in 10 minutes.
  4. Say what the code is for

    "To confirm your address and finish creating your account" or "to sign in as ada@example.com": a person who receives a code they didn't ask for understands that someone is using their address, and a person being talked into reading a code aloud sees what it would unlock.

    Sign in to Acme

    Enter this code in Acme to sign in as ada@example.com:

    739214

    The code expires in 10 minutes.

    Never share this code. Acme will never ask you for it, by phone, email or chat.

    If you didn't try to sign in, ignore this email. Nobody can sign in without this code.

  5. Warn people never to share it

    A common scam is to trigger a real code, then call or message the person pretending to be the product's support, a bank or a friend, and ask them to read it out. The FTC's advice is blunt: anyone who asks for your verification code is a scammer. One sentence in the email, saying you will never ask for it, makes the request easier to spot.

    Sign in to Acme

    Enter this code in Acme to sign in as ada@example.com:

    739214

    The code expires in 10 minutes.

    Never share this code. Acme will never ask you for it, by phone, email or chat.

    If you didn't try to sign in, ignore this email. Nobody can sign in without this code.

  6. Say how long it lasts, and what to do if they didn't ask

    Write when the code expires, so that someone who comes back later knows to ask for a new one. Then say that the email can be ignored if they didn't ask for it: nothing happens without the code.

    Confirm your email address

    Enter this code in Acme to confirm ada@example.com and finish creating your account:

    739214

    The code expires in 10 minutes.

    Never share this code. Acme will never ask you for it, by phone, email or chat.

    If you didn't create an account on Acme, ignore this email.

  7. Send a plain-text version too

    Send the HTML and a plain-text version in the same email. Text-only email apps and some screen readers use it, and spam filters trust emails that have one. Keep the code on its own line, so that it is easy to select there too.

    Plain-text version
    Confirm your email address
    
    Enter this code in Acme to confirm ada@example.com and finish creating your account:
    
    739214
    
    The code expires in 10 minutes.
    Never share this code. Acme will never ask you for it, by phone, email or chat.
    If you didn't create an account on Acme, ignore this email.

Generating and checking the code

Six digits make a million possible codes. That is enough only if nobody gets to try many of them.

  1. Draw six digits from a secure generator

    NIST's guidelines ask for at least six digits, drawn from a cryptographic random generator: randomInt from node:crypto, secrets.randbelow in Python, SecureRandom in Java, never Math.random().

    Keep the code as text: stored as a number, "004817" loses its zeros and no longer matches what the person types.

    Node.js
    import { randomInt } from 'node:crypto'
    
    const code = randomInt(0, 1_000_000)
      .toString().padStart(6, '0')
    // "004817": keep it a string
  2. Limit wrong attempts per account, not per code

    Cancel a code after a few wrong tries, five for example. But if each new code gives five new tries, a script just keeps asking for codes: at five tries per code, 20,000 codes give it about one chance in ten.

    Count the failures on the account, across codes, as NIST requires. After ten failures, make people wait before trying again, longer each time, and tell the owner of the account by email.

    Counted per code
    1. 5 wrong tries, then the code is cancelled
    2. The script asks for a new code, and 5 more tries
    3. 20,000 codes later
    4. About 1 chance in 10 of getting in
    Counted per account
    1. 5 wrong tries, then the code is cancelled
    2. A new code doesn't reset the count
    3. 10 wrong tries on the account: a wait that doubles each time
    4. A hundred guesses take over a week
  3. Make it expire after about 10 minutes

    A code is typed in the minute after it arrives. NIST gives out-of-band codes 10 minutes, GOV.UK gives its codes 15: long enough for a slow email, short enough to leave little time for guessing.

    10 minutes: the code worksafterwards
    1. 10:00Ada signs up and asks for a code
    2. 10:01The email arrives
    3. 10:02She types the code
    4. 10:10The code expires
    5. 10:30A script tries more codes for her account: there is no code left to find
  4. Tie each code to one account and one action

    Store with each code the account it was sent for, what it unlocks (confirming an address, signing in, changing the address) and its expiry. A code sent to confirm an address must not work to sign in or to change the email of the account.

    verification_codes
    user  purpose          expires  tries
    42    confirm_email    10:10    1
  5. Keep earlier codes working until they expire

    Emails can arrive late or out of order. Someone who asked twice types whichever code arrives first. GOV.UK keeps each code valid until its own expiry, rather than cancelling it when a new one is sent. Since failures are counted per account, this gives an attacker nothing more.

    AcmeWorks
    Your Acme verification codeCode sent at 10:03, arrived second
    AcmeStill works
    Your Acme verification codeCode sent at 10:00, arrived late

The field where the code is typed

Half of the experience happens in your app, in the field where the code goes.

  1. Use one field the browser can fill in

    Use type="text" with inputmode="numeric": phones show a number pad, and the code keeps its leading zeros, which type="number" would drop.

    Add autocomplete="one-time-code". Safari then offers the code as soon as it arrives in Messages and, since iOS 17 and macOS Sonoma, in Apple Mail, without leaving the page.

    The code field
    <input type="text" name="code"
      inputmode="numeric"
      autocomplete="one-time-code"
      pattern="[0-9 -]*" required>
  2. One field, not six boxes

    Six separate boxes look neat but break easily: a pasted code lands in the first box, autofill doesn't know where to go, and screen readers announce six fields. A single field with wide letter spacing looks just as clear. GOV.UK's design system uses one field.

    Six boxes
    app.example.com/verify
    Enter the code7The pasted code landed in the first box
    One field
    app.example.com/verify
    Enter the code739214Pasted, typed or filled in: all six digits
  3. Accept the code the way people type it

    People copy spaces, add dashes, paste with a line break. Remove spaces and dashes before checking the code, instead of rejecting it.

    What people type, what you check
    "739 214"  → 739214
    "739-214"  → 739214
    " 739214 " → 739214
  4. Say clearly what went wrong

    Tell an expired code from a wrong one. When the code has expired, say so and send a new one right away; when it is wrong, say how many digits it should have or to check the latest email.

    Vague
    app.example.com/verify
    Invalid code.
    Says what to do
    app.example.com/verify
    This code has expired.We've sent a new one to ada@example.com.
  5. Offer to resend, and to fix the address

    Show the address the code went to and who it comes from, mention the spam folder, and let people ask for a new code after a short wait. At sign-up, let them correct the address: a typo is the most common reason a code never arrives.

    app.example.com/verify
    Check your inboxWe sent a 6-digit code to ada@example.com, from Acme <account@example.com>.______Not there after a minute? Look in your spam folder.Resend in 45 sChange the address

Where codes by email fit, and abuse

A code by email proves that someone can read a mailbox. That is the right proof for some things, and not for others.

  1. Don't count it as a second factor

    NIST's guidelines exclude email from two-factor authentication: a mailbox is often opened with a password, sometimes the same one, and can be reached by whoever stole it. A code by email is a good way to confirm an address, to sign in instead of a password, or to recover an account. As a second step after a password, offer an authenticator app or a passkey.

    Weak fit
    Password, then a code by email
    → one stolen password can
      open both
    Good fit
    Confirm an address at sign-up
    Sign in without a password
    Recover an account
  2. Don't reveal who has an account

    On a sign-in form, show the same message whether the address has an account or not. Otherwise anyone can use it to find out who uses your product.

    Avoid
    app.example.com/login
    No account found for bob@example.com.
    Do
    app.example.com/login
    If an account exists for bob@example.com, we've sent it a code.
  3. Limit how often codes can be requested

    Limit requests per address and per IP, one a minute for example, and add a CAPTCHA if the form is attacked. Without a limit, a script can flood someone's inbox with codes sent from your domain, and the spam reports that follow hurt your real users' emails.

    Bob's inbox, without a limit
    Acme10:00:03
    Your Acme sign-in code
    Acme10:00:02
    Your Acme sign-in code
    Acme10:00:01
    Your Acme sign-in code
    + 297 more

Getting it delivered

The person is waiting on a screen. A code that takes two minutes to arrive feels broken, and one that lands in spam often is.

  1. Send it from your own domain, under your product's name

    Send from an address on your domain, with your product as the sender name, set up with SPF, DKIM and DMARC: the DNS records that prove to Gmail, Outlook and Yahoo that the email comes from you.

    Avoid
    noreply@send-7f3.example.net
    Your Acme verification codeThe code expires in 10 minutes.
    Do
    Acme <account@example.com>
    Your Acme verification codeThe code expires in 10 minutes.
  2. Don't queue it behind your newsletters

    Send codes through a service made for transactional email, apart from your campaigns. A newsletter to 50,000 people can take an hour to go out; a code has to leave in seconds, and must not share the reputation of emails people complain about.

    Newsletters50,000 emails · sent over an hourCodes1 email · sent in seconds

Send it with Kula

Kula sends verification codes and other transactional emails from your own domain within seconds, through an API or SMTP, separately from your newsletters. Free up to 3,000 emails a month.

Start free