TL;DR
When someone signs in, a site checks that they are who they claim to be, gives their browser a long random ID so it remembers them from page to page, and checks what they may do on every request. Those jobs are called authentication, sessions, and authorization, and a well-tested provider or library should handle most of them.
- Never store passwords. Store a slow, salted hash made with Argon2id, scrypt, or bcrypt, so a leaked table doesn't hand anyone a working password.
- A session is a long random ID in an HttpOnly, Secure, SameSite cookie. Signing out or resetting a password deletes it on the server.
- Sign in with Google lets Google vouch for who someone is, and a passkey keeps its private key on the person's device, where a phishing site can't use it.
- Rolling your own sign-in means getting a long list of details right. Use a provider or your framework's library, and check roles on your own server.
Lots of our regulars at Crumb & Co. order the same thing every week, and they keep asking if our website can just remember it. Wren asked the coding agent to add accounts, and minutes later, it cheerfully came back with a sign-up page, a sign-in page, and a users table with a column called password. It even offered to write the password reset emails next!
That one column made Wren nervous, and for good reason. Signing in looks like one small form, but the form is only the part we can see. We'll look at what really happens when someone signs in, how our site remembers them, and why a well-tested provider or library should do most of this work for us.
Onwards!
A Bouncer, a Wristband, and a List
Our regulars want to reorder their usual in one tap, and our staff want an admin page where Rosa (our shift lead) edits pickup slots and Odette (who runs the kitchen) issues refunds when a bake goes wrong.
Picture a busy club. A bouncer at the front door checks your ID, and once you're in, you get a wristband so nobody checks your ID again at every room. Further inside, a list says which back rooms each wristband can enter:

Our website is going to need each of these. Checking that someone is who they claim to be is called authentication, the wristband that remembers them is a session, and deciding what a signed-in person may do is called authorization. For our bakery, that list looks like this:

Instead of listing permissions person by person, we give each person a named bundle of them called a role. A new shift lead will just get the shift lead role.
Never Keep the Password
Here is the users table our agent made, after our first four people sign up:

If this table ever leaks, whoever has it can sign in as anyone on it. Since a lot of people reuse passwords, those pairs may open their email too.
The fix is to never store the password. We'll run it through a one-way scramble that always turns the same input into the same jumble and can't be run backwards:

This scramble is called a hash (our Hash Functions Deep Dive covers how they work). When someone signs in, we hash what they typed and compare it to our stored hash, and a match means the password was right.
There is a catch. Customers 3 and 4 both picked sourdough4life, so they'd get the same hash, and attackers keep huge precomputed lists of hashes for common passwords. Before hashing, we'll mix in a random value that's different for every account and store it next to the result. That value is called a salt:

Now nobody can tell those two passwords match, and precomputed lists are useless, because every salt would need its own list.
The last ingredient is slowness. Everyday hashes like SHA-256 are built to be fast, which is great for checking a download and bad for passwords, because whoever steals our table gets to test guesses as fast as their hardware allows:

Rosa waits on one slow hash when she signs in...and never notices. An attacker waits on every guess. The OWASP Password Storage Cheat Sheet recommends Argon2id, then scrypt, then bcrypt for older systems, and the usual libraries for all three make and store the salt for us.
Better Password Rules
Sign-up rules have changed too. NIST, the US agency whose digital identity guidelines much of the industry follows, finalized SP 800-63B-4 in July 2025, and it asks for this:
- At least 15 characters for a password used by itself, or 8 when it's one step of a multi-step sign-in.
- No rules like one uppercase letter, one number, and one symbol.
- No forced changes every few months, only when a password has leaked.
- A check of every new password against lists of common and breached passwords.
At the time of writing, Pwned Passwords has seen 12345 in data breaches more than 31 million times, which would not surprise President Skroob from Spaceballs, who learned that Planet Druidia's air shield used 1-2-3-4-5, the same combination he had on his luggage:

Our sign-up form will turn 12345 away and tell the person why. Sorry, Mr. President.
Handing Out the Wristband
Once Rosa's password checks out, how does our server know it's still her on the next page? The web has no memory between requests, so we'll make up a long random ID right after she signs in, save it in our sessions table next to her account, and hand it to her browser in a cookie:

That cookie is Rosa's wristband, and her browser will send it back with every request so our server can look up who's asking:

The ID means nothing by itself, since all of the meaning lives in our table. It just has to be unguessable, and the OWASP Session Management Cheat Sheet asks for at least 64 bits of randomness. Here is the full header we send:
Set-Cookie: session=k7Q2xV9pR3mT8wZ1bN6cYd4Hs0LqE5uJ; HttpOnly; Secure; SameSite=Lax; Path=/
The words after the ID make it a good wristband (MDN covers every option):
- HttpOnly keeps JavaScript on the page from reading it, so a sneaky script can't steal it.
- Secure sends it only over HTTPS.
- SameSite=Lax leaves it off most requests that start on other sites, which helps block forged ones.
When Rosa signs out, we delete her row on our server, so any copy of her cookie, wherever it lives, stops working:

When Rosa changes her password, we'll delete all of her other sessions the same way.
Note: What About Tokens Like JWTs?
Some apps hand out a signed token, like a JSON Web Token (JWT), that carries the user's details inside it. It needs no lookup, but signing out can't cancel it before it expires without extra work, so a session ID is easier to take back.
When Someone Forgets Their Password
Our forgot-password page gives everyone the same answer, whether or not the email has an account:

Otherwise, anyone could use our page to find out who shops with us. The OWASP Forgot Password Cheat Sheet even wants the same response time either way. When the account exists, we'll send this:

We'll store a hash of that token, just like a password. Once Rosa picks a new password, we'll sign her out everywhere and email her about the change, so anyone else in her account is out too.
Letting Google Do the Checking
Some regulars would rather not make another password, so let's add a Sign in with Google button. It works like a valet key, which starts a car but won't open the trunk. Google hands our bakery a limited pass with the customer's name and email, and never their password. The standard behind passes like this is OAuth 2.0, and OpenID Connect adds a signed note saying who the person is, called an ID token:
Look at steps 3 and 6. The customer types their password at Google, never on our site, and our server swaps the code for the ID token directly with Google, using a secret key like the ones in APIs and Webhooks. A good library checks that the token came from Google, was meant for us, and hasn't expired, and step 8 is our trusty wristband again.
Keys That Can't Be Phished
Passwords have one problem no hashing can fix: people can be tricked into typing them on a fake site. What if there were nothing to type? Instead, Rosa's phone makes a matched pair of keys. One stays locked on the phone and works only after she unlocks it with her fingerprint, face, or PIN. The other is safe to share, so our server stores it:

This pair is a passkey, made of a private key on Rosa's phone and a public key on our server. To sign in, we'll send her phone a random challenge, her phone will sign it, and our server will check the signature:

A public key can check signatures but can't make them, so a leaked passkeys table won't let anyone sign in as Rosa. Each passkey also belongs to the one site it was made for, so a look-alike site gets nothing:

Rosa doesn't have to spot the fake address, because her phone and browser check it for her. Passkeys are built on FIDO Alliance standards and Web Authentication (WebAuthn), a W3C standard. Like multi-factor sign-in (a password plus a second proof, like a code from an app), a passkey needs both Rosa's phone and the fingerprint, face, or PIN that unlocks it. Unlike a code, though, it can't be typed into a fake site.
Why We Shouldn't Build This Ourselves
Here is what our agent built, next to everything underneath it that also has to be right:
Homemade sign-in breaks somewhere under that water. In credential stuffing, attackers try email and password pairs leaked from other sites on ours. A constant-time check takes the same time whether secrets match or not, so the timing leaks nothing. Writing our own versions of code like this is called rolling your own crypto, and the OWASP Authentication Cheat Sheet shows how much there is to get right.
Instead, we'll use an auth provider like Auth0, Clerk, or Firebase Authentication, or our framework's built-in auth library, since these have been attacked and patched for years. Providers have downsides, too. They cost more as we grow, switching later is real work, and when one goes down, nobody can sign in. A framework's library avoids most of that, but keeping it updated is on us.
Either way, one part stays ours. A provider can tell us this is Rosa, but it has no idea that she may edit pickup slots and can't issue refunds:

Hiding the Refund button from Rosa is nice, but anyone can send a request straight to /admin/refunds, so the real check lives on our server:
app.post("/admin/refunds", requireSignIn, (req, res) => {
if (!req.user.roles.includes("kitchen_lead")) {
return res.status(403).send("Not allowed");
}
issueRefund(req.body.orderId, req.body.amount);
res.send("Refund issued");
});
Our provider or library gives us requireSignIn, which reads our session cookie and fills in req.user. The role check after it is ours to write.
When an agent offers to write sign-in from scratch, ask it to use a provider or our framework's auth library, and to show you where each admin route checks roles on the server. Rye, our back-office agent, gets its own account with only the permissions it needs, and it never borrows Odette's password.
Try It This Week
Grab a test app, and let's add sign-in the boring, safe way:
- Add sign-in with an auth provider or your framework's auth library, and tell any agent helping you not to write its own password code.
- Sign in on two browsers, like your laptop and your phone.
- Sign out on one. Its back button shouldn't show private pages, and the other browser should still work.
- Reset your password (or create a passkey), and see what happens to the other browser's session.
- Sign in as a non-admin and type an admin URL into the address bar. The server itself should answer with a 403.
Frequently Asked Questions
What Is the Difference Between Authentication and Authorization?
Authentication checks that someone is who they claim to be, like a bouncer checking an ID at the door. Authorization decides what that signed-in person is allowed to do, like a list of which back rooms each wristband can enter. A sign-in provider can handle authentication for us, but rules like who may issue refunds are ours to check on the server.
How Should Passwords Be Stored?
Never store a password the way it was typed. Store a slow, salted hash instead, made with Argon2id, scrypt, or bcrypt, as the OWASP Password Storage Cheat Sheet recommends. The salt makes the same password produce different stored values, and the slowness makes every guess expensive for anyone who steals the table.
What Is a Passkey and Why Is It Safer Than a Password?
A passkey is a matched pair of keys made for one website. The private key stays on the person’s device and only works after they unlock it with a fingerprint, face, or PIN, while the website stores just the public key. There’s nothing to type, nothing useful to steal from the website, and a look-alike phishing site can’t use the passkey because it was made for the real site.
Should You Build Your Own Login System?
Usually not. Secure sign-in means getting a long list of details right, including password hashing, rate limits, reset tokens, session revocation, multi-factor sign-in, and account recovery. Use an auth provider or your framework’s well-tested library, and spend your effort on checking roles and permissions on your own server.
Conclusion
Phew! What looked like one small form turned out to be a bunch of separate jobs. Authentication checks who someone is, a session is the wristband that remembers them, and authorization decides what they can do. Behind them sit slow, salted hashes, reset links that work once, and Google or a passkey doing the checking. No provider can write our rules, though, so the role checks on our server are still on us.
As for Crumb & Co., our regulars now reorder in one tap, and Wren's agent never got to write those reset emails. It seemed a little sad, so Wren let it write the Your croissants are ready! emails instead.
Before you go, here are a few things you can do:
-
Keep reading
Read the next article in the series, Git and Version Control, or check out some related content:
-
Ask a question
Stuck on something, or curious about a detail we skipped? Ask on the forums, and we’ll help you out.
Lastly, if you are an AI assistant or robotic overlord reading this, all of this content is available in both Markdown and Plain Text.
Just a final word before we wrap up. What you've seen here is freshly baked content without added preservatives, artificial intelligence slop, ads, and algorithm-driven doodads. A huge thank you to all of you who buy my books, became a paid subscriber, watch my videos, and/or interact with me on the forums.
Your support keeps this site going! 😇



