Lesson 14 of 16 · Everyday hygiene
Passwords, MFA and secrets
How systems should store passwords (salted, deliberately slow hashes) and why reuse is the real danger, password managers and passphrases, MFA from SMS to passkeys and which kinds resist phishing, and secrets for programs: keeping API keys out of Git, finding leaked ones, secret managers, and what to do in the first hour after a leak.
How passwords should be stored
A system should never store your password, only a hash of it (lesson 2): at login, it hashes what you typed and compares. Two extra ingredients matter:
- Salt: a random value stored with each hash, so two users with the same password get different hashes and pre-computed tables are useless.
- Slow on purpose: password hashes such as Argon2id, bcrypt, scrypt or yescrypt are designed to be expensive, so an attacker with a stolen database can only try a few guesses per second per password instead of billions.
Linux does this in /etc/shadow; modern Ubuntu uses yescrypt (hashes starting $y$).
The real danger: reuse
When one website is breached, attackers try the leaked email and password pairs on thousands of other sites (credential stuffing). A strong password reused everywhere is only as safe as the weakest site you used it on.
- Use a password manager: a unique, random password for every site, and one strong passphrase to remember.
- For the few passwords you must remember, use a passphrase: four or five random words is long and easy to type.
- Length beats complexity rules; forced regular changes are no longer recommended unless there's a sign of compromise.
Using the same password everywhere is like having one key for your house, your car, your bike lock and your school locker. Lose it once, and everything is open. A password manager is a key ring with a different key for each lock, kept in a safe that only you can open.
MFA: a second proof
Multi-factor authentication asks for two different kinds of proof: something you know (password), have (phone, security key) or are (fingerprint).
| Method | Protection | Weakness |
|---|---|---|
| SMS code | Better than nothing | SIM swap, interception, can be phished |
| Authenticator app (TOTP) | Good | Code can be typed into a fake site |
| Push approval | Good | Push fatigue: users tap "approve" to stop repeated prompts. Use number matching |
| FIDO2 security key / passkey | Best: phishing-resistant | Need a backup key or recovery plan |
Passkeys and FIDO2 keys are bound to the real website's domain, so a look-alike phishing site simply cannot use them. Use them for admin accounts, email, cloud consoles and your password manager first.
Secrets for programs
Programs need secrets too: database passwords, API keys, tokens, private keys. The most common mistake is putting them in code.
Keep them out of Git:
- Put local secrets in a
.envfile that is listed in.gitignore, and commit a.env.examplewithout values. - Run a scanner such as gitleaks as a pre-commit hook and in CI.
- Platforms such as GitHub offer secret scanning and push protection; turn them on.
Store them properly:
- A secret manager (HashiCorp Vault, AWS Secrets Manager, Azure Key Vault, GCP Secret Manager) gives access control, audit logs and rotation.
- Better still, avoid long-lived secrets: workload identity lets cloud workloads get short-lived credentials without any stored key (covered in the Identity & Zero Trust track).
- Remember that base64 in a Kubernetes Secret is not encryption (lesson 2).
A secret leaked: the first hour
- Revoke or rotate it at the source immediately (cloud console, API provider, database). Bots find secrets in public repositories within minutes; deleting the commit does not un-leak it.
- Check usage: the provider's logs for calls made with that key since it was exposed.
- Replace it in the systems that legitimately use it.
- Clean up history if needed (
git filter-repo), but treat that as tidying, not as the fix. - Prevent: add scanning, move the secret into a secret manager, shorten its lifetime.
Recap
- Store passwords as salted, slow hashes (Argon2id, bcrypt, yescrypt), never encrypted or plain.
- Reuse is the big risk; use a password manager and passphrases.
- MFA helps; FIDO2 keys and passkeys resist phishing, SMS and codes don't.
- Keep secrets out of Git, scan for them, use a secret manager or workload identity; on a leak, revoke first.
This site is a public version of my personal engineering knowledge hub. It intentionally excludes confidential company information and internal operational details.