Back to blog

Someone knocks at the API door: how do you know who?

Thắng Đoàn
Thắng Đoàn

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

Share:

Recommended for you

Enjoyed this article?

Subscribe for new articles. No spam. Unsubscribe anytime.

No pasting. This is the challenge.0/200

Typed live, never pasted.