Authentication answers "who are you?". Authorization, a separate step, answers "what may you do?". A mistake in either one lets the wrong person in.
Factors
Proof usually comes from something you know (a password), have (a phone or security key) or are (a fingerprint). Multi-factor authentication (MFA) requires different kinds, so a stolen password alone is not enough. Passkeys and security keys based on WebAuthn also resist phishing, because the credential is tied to the real site's domain.
How credentials travel
HTTP defines the Authorization header. With Basic authentication the username and password are only Base64 encoded:
$ echo 'YWxpY2U6c2VjcmV0' | base64 -d
alice:secretEncoding is not encryption, so Basic must only be used over HTTPS. Websites more often use a login form that sends a POST over HTTPS and then creates a session. APIs often use tokens, sent as Authorization: Bearer <token>.
A missing or wrong credential normally gets 401 Unauthorized:
$ curl -i https://api.example.com/me
HTTP/2 401
www-authenticate: BearerStore passwords safely
Never store passwords in plain text, and do not use a fast hash such as plain SHA-256. Use a slow password hashing function such as Argon2id or scrypt (bcrypt mainly in older systems), with a unique random salt for each password. A good library handles the salt for you. The slowness makes guessing expensive if the database leaks.
Protect the login
- Limit repeated attempts, and slow them down.
- Reply with the same message for an unknown user and a wrong password, so accounts are not revealed.
- Allow long passwords and reject known breached ones.
- Make password reset links random, short-lived and single-use.
- Log successes and failures, but never the password.
Prefer a well-tested library or identity provider over writing your own.
Try it
On an application you own, try a wrong password and an unknown username. Compare the messages, status codes and timing. They should not tell you which accounts exist. Then check that the logs record the attempt without the password. The accounts and access files lab shows how Linux stores account data.
Check your understanding
Authentication
All 3 sections · no timer
Unlimited retries
Questions from every section are combined into one assessment. Answer them all correctly to complete the article.
Your completion saves in this browser. Sign in to sync it to your account.