What is Authentication?
Authentication is the process of proving who you are to an application. When you type an email and password, scan a fingerprint, or enter a one-time code, the app checks that proof and decides whether you really are the account owner. Every app that has private data, from a chat app to an admin dashboard, needs authentication before it can show anything personal.
Authentication is not authorization
These two words sound alike and are often mixed up. Authentication answers "who are you?". Authorization answers "what are you allowed to do?". A logged-in student and a logged-in admin are both authenticated, but only the admin is authorized to delete users.
| Authentication | Authorization | |
|---|---|---|
| Question | Who is this user? | May this user do this action? |
| Happens | First, at login | On every protected action |
| Typical failure code | 401 Unauthorized | 403 Forbidden |
| Example | Checking a password | Checking a user's role is "admin" |
The naming of status 401 is confusing, since it says "Unauthorized" but really means "not authenticated". Use 401 when the request has no valid login, and 403 when the user is known but lacks permission.
Ways a user can prove identity
Proof usually falls into three groups, called factors:
- Something you know: a password or PIN.
- Something you have: a phone receiving an OTP, an authenticator app, or a hardware key.
- Something you are: a fingerprint or face scan.
Combining two different factors is called two-factor or multi-factor authentication. It means a leaked password alone is not enough to break into an account.
Why web apps need to remember the login
HTTP is stateless: the server treats each request as brand new and does not remember the previous one. If nothing else happened, the user would have to send their password with every click. Instead, after a successful login the server gives the client something to show on later requests. There are two common approaches.
- Server sessions: the server stores session data and sends the browser a cookie holding a random session id.
- Tokens: the server signs a token, often a JSON Web Token, and the client sends it in a header. The server verifies the signature instead of looking anything up.
Single page apps that talk to a separate API often use tokens, sent like this:
const response = await fetch('/api/profile', {
headers: {
Authorization: `Bearer ${token}`,
},
});
if (response.status === 401) {
// token missing or expired: send the user to the login page
}
A mistake to avoid: checking only in the frontend
Hiding a button or a page in React does not protect anything. Anyone can open the browser's developer tools, call your API directly, or edit JavaScript in the page. The real check must always happen on the server, which verifies the session or token on every protected route. The frontend check exists only to give a nicer experience, such as redirecting to a login screen.
Also never store plain-text passwords on the server. Passwords should be hashed with a slow algorithm made for the purpose, such as bcrypt or Argon2, so a database leak does not expose them directly.
What to remember
Authentication confirms identity; authorization decides permissions. Because HTTP forgets every request, apps hand out a session cookie or a token after login, and the server must verify it every time. The next lesson looks at why each approach exists and how they work in practice.
Ready to master real-world web development?
Learn HTML, CSS3, Bootstrap and JavaScript hands-on with mentor-led sessions.