Credentials are the keys to every account, which makes them the most attacked asset on the internet. This lesson covers how to store passwords correctly as a developer, how to choose them wisely as a user, and why multi-factor authentication changes the game.
If your database is ever leaked, and you should assume one day it might be, plaintext passwords hand attackers every account instantly, including accounts reused on other sites. Encrypting passwords is also wrong: encryption is reversible, and the decryption key sits on the same servers. The correct tool is a one-way cryptographic hash.
A hash function turns any input into a fixed-length digest that cannot be reversed. But not all hashes are suitable for passwords. Fast hashes such as MD5 and SHA-256 can be guessed at billions of attempts per second on modern GPUs. Password storage needs three properties:
// Secure password storage with bcrypt (Node.js)
const bcrypt = require('bcrypt');
async function registerUser(email, password) {
const hash = await bcrypt.hash(password, 12); // cost factor 12, salt built in
await db.users.insert({ email, passwordHash: hash });
}
async function verifyLogin(email, password) {
const user = await db.users.findOne({ email });
if (!user) return false;
return bcrypt.compare(password, user.passwordHash); // constant-time compare
}Note that bcrypt generates and embeds the salt automatically, and bcrypt.compare avoids timing side channels. Never write your own comparison with === on secrets.
Modern guidance from NIST has moved away from forced complexity rules and mandatory 90-day rotations, which push users toward predictable patterns like Summer2026!. Better practice:
correct-horse-battery-staple are strong and memorable.MFA requires two or more of: something you know (password), something you have (phone, hardware key), something you are (fingerprint). Even a perfect phishing attack that captures a password fails if a second factor is required. Options ranked roughly by strength:
As a developer, offering TOTP is often a single library away, and passkey support is now built into all major browsers and platforms.
Next lesson: How HTTPS and TLS Keep You Safe, where we follow a credential's journey across the network.