Script Valley
JWT & Session Auth: Deep Dive
Authentication Fundamentals/Assessment

Practice & Assessment

Test your understanding of Authentication Fundamentals

Multiple Choice Questions

5
1

A user logs in successfully but receives a 403 response when accessing /admin. What does this indicate?

2

Which cookie attribute prevents JavaScript from reading an auth cookie, protecting against XSS attacks?

3

What is the primary advantage of stateless authentication over stateful sessions?

4

Why is bcrypt preferred over SHA-256 for password hashing?

5

Where is the safest place to store a JWT access token in a browser-based SPA to mitigate XSS risk?

Coding Challenges

1
1

Implement a bcrypt Registration and Login Endpoint

Build two Express endpoints: POST /register accepts { email, password }, hashes the password with bcrypt (cost 12), and stores the user in an in-memory array. POST /login accepts the same shape, finds the user by email, compares the password using bcrypt.compare, and returns { success: true } or a 401 error. Do not use a database โ€” an in-memory array is fine. Input: valid email + password string. Output: JSON response with success flag or error message. Estimated time: 15-20 minutes.

Easy

Mini Project

1

Auth Concepts Cheat Sheet API

Build a small Express API with three routes: GET /concepts returns a JSON array of auth terms (authentication, authorization, stateful, stateless, Bearer token, HttpOnly cookie) each with a one-sentence definition you write. POST /quiz accepts { term, definition } and returns { correct: true/false } by comparing against your stored definitions (case-insensitive). POST /register and POST /login endpoints using bcrypt hashing and an in-memory user store. The login endpoint should return a dummy token string on success. This project uses bcrypt, proper HTTP status codes (200, 401, 404), and demonstrates the auth vs authz distinction through route design.

Easy
Practice & Assessment โ€” Authentication Fundamentals โ€” JWT & Session Auth: Deep Dive โ€” Script Valley โ€” Script Valley