Skip to content
Paul Yeager
← Journal

AuthenticationSecurityBuild

Stop building login forms: authentication is not your product

Why rolling your own sign-in is the most expensive shortcut in web development, what a minimum-viable secure login needs, and how to add it in an afternoon.

By Paul E. Yeager · · 6 min read

Almost every web project starts the same way: “we just need users to log in.” Two weeks later there is a password-reset flow, an email-verification flow, rate limiting, a session store and an on-call rota for credential-stuffing attacks. A login form is the smallest visible part of authentication, and the rest is the part that hurts.

What “just login” actually includes

  • Password storage with a modern, slow hash, never a fast one
  • Account enumeration protection: identical responses for known and unknown emails
  • Rate limiting and bot defence on every credential endpoint
  • Email verification and a safe, expiring password-reset link
  • Session or token handling with sane expiry and revocation
  • Optional two-factor authentication and recovery codes
  • Audit logs you will wish you had on the day of an incident

The OWASP Authentication Cheat Sheet is a good yardstick. If you cannot tick every item, then you are either shipping a risk or committing to a maintenance job that will outlive the feature that needed it.

When to build, and when to buy

SituationMy advice
Sign-in is a supporting feature of your productUse a hosted authentication service
You need enterprise SSO or SAML for large customersUse a full identity platform
Authentication is your productBuild it, with a dedicated security owner
You need email/password with JWTs, fastA small REST service is plenty (see below)

A pragmatic setup

This site uses AuthFlow, an email/password JWT service I also build. Visitors can create an account and comment on the journal. The browser never sees the API key: a small server-side route talks to AuthFlow, stores the session in an HttpOnly cookie, and checks it again before every write. That separation is the part worth copying, whichever provider you choose.

  1. Create a tenant for your site and keep its API key in a server-side environment variable.
  2. Route sign-up and sign-in through your own server, so the key never reaches the browser.
  3. Store the session token in an HttpOnly, SameSite cookie.
  4. Validate the session on the server before you accept any write.
  5. Link your own records (comments, orders, profiles) to the user's email or ID rather than copying their credentials anywhere.

The result is an hour or two of integration rather than weeks of work, and the sort of boring sign-in your users never think about. If you want help wiring it into an existing app, that is a service I offer.

Share this articleLinkedInXEmail

Discussion

Loading comments…