Authentication Tutorials: Passwords, HTTP Basic Auth and JWT
3 posts on authentication, newest first.
This page collects GeekCoding101’s hands-on authentication tutorials: password login, HTTP Basic Authentication and JWT, each built from scratch in Node.js. If you’re new to the topic, read them in that order, from the simplest scheme to the most flexible.
The posts belong to the Auth101 series. They are free to read, with no sign-up.
Where to start
- Password Authentication in Node.js: A Step-by-Step Guide. This covers the most common way to verify a user: a username and password checked by your server. Start here if you’ve never built a login flow.
- HTTP Basic Authentication Explained (RFC 7617). This post covers:
- how the
Authorizationheader carries a Base64-encodedusername:password - why Basic Auth must run over HTTPS
- a Node.js and TypeScript middleware you can drop into a project
- how the
- Unlocking Web Security: Master JWT Authentication. This post covers JWT claims, token structure and signing algorithms. It then builds JWT authentication from scratch in Node.js, with complete, runnable example code.
The three methods at a glance
| Method | What the client sends | What the server checks | Typical fit |
|---|---|---|---|
| Password login | Username and password, usually once through a login form | The password against a stored (hashed) value, then issues a session or token | User-facing sign-in |
| HTTP Basic Auth | Authorization: Basic <base64(username:password)> on every request | The decoded credentials, on every request | Internal tools and simple APIs, over HTTPS only |
| JWT | Authorization: Bearer <token> | The token’s signature and claims, such as expiry | Stateless APIs and service-to-service calls |
All authentication posts
Authentication vs. authorization
Authentication answers who are you? Authorization answers what are you allowed to do?
Every post on this page is about the first question: proving identity with a password, credentials in a header, or a signed token. Deciding what a verified user may access is a separate step that comes after.
- 11 min read
JWT Authentication in Node.js From Scratch
How a JWT works (header, claims, signature, HS256 vs RS256), then build JWT access and refresh tokens from scratch in Node.js and TypeScript.
- 7 min read
HTTP Basic Authentication Explained (RFC 7617)
How HTTP Basic Auth works: the Authorization header, Base64 username:password, why it needs HTTPS, plus a Node.js and TypeScript middleware example.
- 10 min read
Node.js Password Authentication with bcrypt and TypeScript
Build register and login routes in Express and TypeScript, hash passwords with bcryptjs, and see what each part of a bcrypt hash ($2a$10$…) means.
FAQ
Is HTTP Basic Authentication secure? Only over HTTPS. Base64 is an encoding, not encryption, so anyone who can read the request can decode the username and password. The credentials are also sent with every request, so plain HTTP exposes them every time.
Should I use JWT or server-side sessions? It depends on where you want state to live:
- Sessions keep state on the server. They are easy to revoke but need shared storage when you run several servers.
- JWTs carry signed claims in the token itself. The server can verify them without a lookup, but tokens are harder to revoke before they expire.
The JWT post explains the token structure so you can judge the trade-off.
What’s the difference between JWT and Basic Auth? With Basic Auth, the client sends the real username and password on every request. With JWT, the client signs in once, then sends a signed token that the server verifies instead of re-checking the password.
Do I need to know Node.js to follow along? The examples are written in Node.js, and the Basic Auth post also includes a TypeScript middleware. Basic JavaScript is enough to follow the code. The concepts (headers, encoding, signatures, claims) apply in any language.