Someone knocks at the API door: how do you know who?
FotoFlow has a million users with real photos and real payment details, and this week the first support tickets arrive: "someone logged into my account." The intruder used the correct password. That is the moment authentication stops being a signup form and becomes a defense system.
Hash passwords slowly
The accounts table stores no passwords. It stores a hash: the output of a deliberately slow, salted function such as argon2id or bcrypt. The salt is random per user, so two people with the same password still hash differently, and the slowness, around 100 ms, makes brute-forcing stolen hashes painfully expensive while one login stays instant.
Fast hashes like MD5 or SHA-256 alone are wrong here: a GPU tries billions per second. Never store a password: store a slow, salted hash of it.
The session cookie is the real key
After login, the server sends a session cookie, and its flags matter more than its content: HttpOnly so JavaScript cannot read it, Secure so it only travels over HTTPS, and SameSite so another site cannot make the browser send it silently. Steal the cookie and you steal the session; the flags are the lock.
Resets and reused passwords
The reset flow gets the same discipline: a single-use token that expires in 15 minutes, and the new password choice sent only in the reply to the registered email, never in the email body itself. Most "hacks" are simpler: credential stuffing. About 0.5 percent of people reuse a password that already leaked elsewhere, so attackers replay known email and password pairs from old breaches. Rate-limit login attempts per account and per IP, and screen new passwords against breach lists such as Have I Been Pwned. A password reused from another leak will open accounts here unless you check.
Passkeys and delegated login
For stronger accounts, passkeys beat SMS codes: the key is bound to your domain, so a phishing page cannot use it. And FotoFlow does not have to own identity at all: OpenID Connect lets users log in with Google or Apple, which removes password storage, resets, and breach screening for those users entirely.
What this does not solve
Tokens leak too: a stolen access token works until it expires. Short-lived tokens shrink the blast radius of every leak. So the API issues access tokens valid for minutes and refresh tokens that can be revoked, stored server-side and rotated. That is also the honest limit of this part: everything above proves *who* is knocking. Whether that person may open album 1043 is a different question.
Your password leaked from another service last year. Which of your accounts would still stand, and why?
An attacker holds a valid session cookie. What stops them, and for how long?
Identity is solved, but a logged-in user asking for a stranger's album is the next incident waiting. Next in the series: Logged in, yes. But allowed to open this private album?
Sources
OWASP Authentication Cheat Sheet
OAuth 2.0 and OpenID Connect
JWT.IO
Recommended for you
- Craft & Skills
One server, 10 million users: how does a photo app survive that?
A 40-post series that follows FotoFlow, a photo app, from one server and 100 users to 10 million users with direct messages. One problem, one fix, one honest cost at a time.
- Craft & Skills
Ten million users want direct messages: could you design the chat system?
The final design: 20 million open sockets and a promise that every message arrives, in order, exactly once. Dumb gateways, a connection registry, store-first durability and sync by cursor.
- Craft & Skills
Five million home feeds: how do you build the page everyone opens?
The home feed must load in 200 ms from two hundred followed accounts. Fan-out on read melts at 4.6 million lookups a second; fan-out on write melts on celebrities; the hybrid survives both.
- Craft & Skills
FotoFlow wants short share links: could you design one today?
The first full design walkthrough: turn a one-line brief into numbers, the simplest system, then fix codes, caching, storage and abuse one bottleneck at a time. The method is the point.
Enjoyed this article?
Subscribe for new articles. No spam. Unsubscribe anytime.
Typed live, never pasted.