Passwords, Login Defenses, and Account Enumeration
Compare correct, incorrect, and unknown-account logins, then inspect password verification, guessing limits, and session creation.
You’re reading a preview. Premium includes the full lesson and specialist practice. View the full curriculum.
Try three logins to the same app: the right password for Mia, a wrong password for Mia, and a password for an account that does not exist. Only the first should move toward a completed login.
What can an outside observer learn from the other two responses? A different message, response shape, or amount of work can reveal whether the account exists. That is account enumeration.
| Attempt | Intended result |
|---|---|
| Known account, correct password | Continue through the configured login factors |
| Known account, wrong password | Fail without a completed session |
| Unknown account | Fail without unnecessarily revealing account existence |
We'll compare those paths, then examine password verification, guessing limits, and the point where a full session is created.
Identify what is stored and what is verified
A password database should hold a one-way adaptive verifier with the algorithm, salt, and cost information required by the chosen library. A fast digest is not an appropriate password verifier merely because its output looks random. Reversible encryption creates a different key-compromise risk and is rarely the intended password-storage design.
Use the framework or maintained library's verification function. It should understand its encoded verifier format and compare safely. Do not reimplement hashing or compare a newly generated salted hash string with the saved string. Fresh salts intentionally produce different encodings for the same password.
async function verifyPasswordRecord(user, suppliedPassword) {
if (typeof suppliedPassword !== 'string') return false;
if (suppliedPassword.length > policy.maxPasswordCharacters) return false;
return passwordLibrary.verify(user.passwordVerifier, suppliedPassword);
}
async function changePassword(actor, newPassword) {
requireRecentAuthentication(actor);
validateNewPasswordPolicy(newPassword);
const encoded = await passwordLibrary.hash(newPassword, configuredCost);
await users.replaceVerifier(actor.userId, encoded);
await sessions.revokeOtherSessions(actor.userId);
}
The functions are contract outlines, not a specific library API. Review encoding, maximum input size, Unicode handling, and algorithm-specific limits. Never silently trim or normalize an entered password differently at registration and verification. If migrating legacy verifiers, verify with the old supported scheme and rehash after a successful login under the new policy.
Inspect the boundaries before and after expensive verification.
Parse. Reject malformed shapes and unreasonable work before verification.
const input = parseLogin(body);
await limiter.requireBudget(trustedContext, input.account);
Verify. Use stored algorithm metadata and a maintained verification function.
const verifier = user?.passwordVerifier ?? dummyVerifier;
const valid = await passwords.verify(verifier, input.password);
Transition. A valid first factor enters restricted pending state when MFA is required.
if (!user || !valid) return genericFailure();
return beginServerOwnedFactorFlow(user);
Review question: Storage, online budgets, public responses, and final identity are independent review targets.