# Passwords and Signing In

Accounts start with a password you must never be able to read. Hash passwords with bcryptjs, build sign-up and sign-in routes, then keep a person signed in: with a session cookie, or with a token (JWT) the way most APIs do, and know which fits when.

Updated: November 19, 2026

## [Passwords](https://www.ask-codey.com/courses/nodejs-in-depth/topics/node-auth-passwords)

1. [Storing Passwords Safely: Hashing](https://www.ask-codey.com/lessons/node-auth-passwords-and-hashing) (Journeyman): An app never keeps a password itself; it keeps a bcrypt hash, a one-way fingerprint made with a random salt and a slow cost factor, and it checks each sign-in with bcryptjs's compare.
2. [Sign-Up and Sign-In Routes](https://www.ask-codey.com/lessons/node-auth-sign-up-and-sign-in) (Journeyman): A sign-up route hashes the password, saves the student behind a unique index on email and answers 409 for an email that's taken, and a sign-in route checks the password with compare and answers one vague 401 for any mistake, never sending a hash back.

## [Staying Signed In](https://www.ask-codey.com/courses/nodejs-in-depth/topics/node-auth-staying-signed-in)

1. [Sessions and Cookies](https://www.ask-codey.com/lessons/node-auth-sessions-and-cookies) (Journeyman): A session keeps a student signed in the way a coat check does, with the record on the server and only a random ticket in the browser's cookie, and express-session sets it up with the HttpOnly, Secure and SameSite flags; it's the simpler choice for one website on its own server.
2. [Tokens: Signing In with a JWT](https://www.ask-codey.com/lessons/node-auth-tokens-jwt) (Journeyman): A JWT is a signed token the server hands out at sign-in and each request sends back in an Authorization Bearer header; jsonwebtoken's sign and verify make and check it, anyone can read its payload, and it fits APIs that apps and other servers call.

## [Exercise: Study Group Sign-In](https://www.ask-codey.com/courses/nodejs-in-depth/topics/exercise-node-study-group-sign-in)

1. [Exercise: Study Group Sign-In](https://www.ask-codey.com/lessons/exercise-node-study-group-sign-in) (Journeyman): Finish the study group's sign-up, sign-in and /me routes, saving only bcrypt hashes, refusing an email that's taken with 409, answering every sign-in mistake with one 401 and handing back a JWT that lasts an hour, and let Supertest's tests check every answer against a throwaway MongoDB.

Source: https://www.ask-codey.com/courses/nodejs-in-depth/chapters/node-passwords-and-signing-in
