When a database authenticates a client with a password using SCRAM-SHA-256 challenge-response, what does that protocol give you that sending the password over the connection (or sending a simple MD5 hash of it) does not?
answer
- Password never on the wire; a proof is
- Per-user random salt + PBKDF2 iterations
- Stored verifier cannot produce a proof — only verify one
- Old hashed schemes: stored hash is password-equivalent
- Mutual auth + channel binding blocks the MITM relay
basics
~20 sThe password never crosses the wire in any replayable form. Both sides prove knowledge over a random per-session nonce, the server also proves itself to the client, and the stored verifier is a salted, iterated derivative that an attacker who steals it cannot directly replay to log in.
solid answer
~60 sWith plaintext or trivially hashed passwords, whatever crosses the wire *is* the credential: capture it and you can replay it. Simple MD5-style schemes fix replay with a per-connection salt, but the value stored in the catalog is still password-equivalent — steal the hash and you can authenticate — and it is cheap to crack offline. SCRAM-SHA-256 (RFC 7677) fixes both. The stored verifier is derived with PBKDF2 using a **per-user random salt and a high iteration count**, so an offline attack on a leaked catalog is expensive. During the exchange, client and server mix in random nonces from both sides and the client sends a *proof*, not the password or the verifier. What the server stores is deliberately insufficient to reconstruct that proof, so a dump of the credential table is not directly replayable. SCRAM is also **mutually authenticating**: the server returns a signature the client verifies, so a rogue endpoint cannot silently harvest logins. With channel binding, the exchange is additionally tied to the TLS connection, defeating relay through a man-in-the-middle proxy.
go deeper
It is enough to say the password itself never travels and that the server stores a salted, slow-to-crack derivative rather than the password.
Separate the two threats explicitly: wire replay versus theft of the stored verifier, and note that older hashed schemes leave the stored value password-equivalent.
Add the migration reality — verifiers must be re-derived, legacy drivers break — plus mutual authentication and channel binding against relay attacks.
Position password authentication against the alternatives: a centrally issued short-lived credential or a certificate removes the long-lived shared secret entirely, which matters more at scale than the hash algorithm.
## The problem with password authentication A password scheme has to survive three separate threats: 1. **Wire capture / replay** — someone reading the connection must not learn something they can present later. 2. **Server-side theft** — someone who dumps the catalog of stored credentials must not gain the ability to log in, and must face expensive offline cracking. 3. **Impersonation of the server** — a client tricked into connecting to a rogue endpoint must not hand over a usable secret. Naïve schemes fail all three; older challenge-response schemes fix only the first. ## Plaintext The client sends the password; the server compares it to what it stores. Everything hinges on transport encryption. Without TLS, anyone on the path has the credential; with TLS, the database server still sees the real password, which matters when that password is also the user's directory password. ## MD5-style challenge-response A classic improvement: the server stores `hash(password + username)` and sends a random per-connection salt; the client returns `hash(stored_hash + salt)`. Wire capture no longer yields a replayable value for a *different* connection. But two weaknesses remain: - The stored value is **password-equivalent**. It is all the client ever needs to compute a response, so an attacker who reads the catalog can authenticate as that user without ever cracking anything. - The digest is unsalted-per-user in any meaningful sense (the "salt" is the username) and uses a single fast hash pass, so leaked values fall quickly to rainbow tables and GPU cracking. ## What SCRAM changes SCRAM (Salted Challenge Response Authentication Mechanism) does a four-message exchange. Conceptually: 1. Client sends its name and a client nonce. 2. Server replies with the user's **random salt**, an **iteration count**, and a combined nonce. 3. Client derives a key from the password via **PBKDF2(password, salt, iterations)**, then sends a *proof* computed over the full transcript of the exchange. 4. Server verifies the proof and returns its own signature, which the client checks. The consequences: - **No replay.** The proof is bound to nonces contributed by both sides, so it is useless on another connection. - **The stored verifier is not the credential.** The server keeps derived values that let it *verify* a proof but not *produce* one. Stealing the catalog therefore does not hand an attacker a working login — it hands them material for an offline attack. - **That offline attack is expensive.** Per-user random salt kills precomputation and shared work across accounts; the iteration count (tens of thousands of PBKDF2 rounds) multiplies the cost of every guess. - **Mutual authentication.** Because the server must return a valid signature, a rogue server that merely collects the client's proof cannot convince the client, and the collected proof is not replayable elsewhere. - **Channel binding** (the `-PLUS` variant) folds the TLS endpoint into the transcript, so an attacker who terminates TLS in the middle and relays the exchange to the real server fails verification. ## What it does *not* do - It does not encrypt your data. SCRAM protects the credential exchange only; you still want TLS for the session. - It does not make weak passwords safe — iteration counts raise the cost per guess, they don't rescue `postgres123`. - It grants **no privileges**. It only establishes which role you are; every subsequent statement is still authorized against the catalog. - It says nothing about *which* connections are even allowed to use passwords — that is decided beforehand by the host-based rules. ## Operational notes Migrating an installation from an MD5-style scheme to SCRAM is not a config flip: the stored verifier has to be recomputed, which requires each user to set their password again after the new algorithm is made the default. Old client drivers that predate SCRAM cannot authenticate at all and must be upgraded — the failure looks like an outright authentication failure, not a warning. Verify that clients negotiate the intended mechanism rather than trusting configuration. ## What interviewers listen for The distinction most candidates miss is the second threat: they explain that "the password isn't sent in the clear" and stop. The stronger answer separates wire protection from verifier protection, and points out that in older hashed schemes the stored hash is itself sufficient to authenticate.
- An installation switches its password algorithm setting from MD5 to SCRAM. Why do users still authenticate with the old scheme afterwards?The setting only controls how a verifier is computed when a password is *set*. Existing accounts still carry their old stored verifier, so the server keeps negotiating the old mechanism for them. Every account must set its password again to be re-derived under SCRAM, and only once no legacy verifiers remain can you require SCRAM in the host-based rules.
- If SCRAM already protects the credential, why still require TLS on the connection?SCRAM secures the authentication exchange, not the session. Without TLS, query text, parameters and result rows travel in the clear and can be read or modified in flight. TLS also enables channel binding, which is what stops an attacker who terminates the connection in the middle from relaying the SCRAM exchange to the real server.
saying these in an interview costs you the question
- "SCRAM encrypts the password" — it is a proof-of-knowledge exchange, not encryption
- Thinking any stored password hash is safe to leak because it is "hashed"
- Believing SCRAM removes the need for TLS on the connection
- Assuming changing the password-algorithm setting retroactively upgrades existing accounts
- Claiming a captured challenge-response can be replayed to any later connection