LEARN. PRACTICE. EXPLAIN.
Learning paths & interview practiceP
← Build a login system
BUILD → VERIFY → EXPLAIN · STEP 2 OF 6

Log in and issue a session

Verify credentials and return an unpredictable, limited-lifetime identifier.

UNDERSTAND

Bring these concepts with you

BUILD

Your implementation

  1. Implement login with the supplied matches helper and dummy password record for missing users. Return the same credential error for missing accounts and wrong passwords.
  2. Generate a fresh random token for each successful login. Store only its hash, user ID, and expiry in sessions.
  3. Return the raw token to the HTTP adapter. Do not return it in the JSON response or write it to logs.
function login(id, password) {
  // Verify, generate a token, store its hash and expiry, return token.
}
Need a hint?
  • randomBytes(32).toString("base64url") provides an opaque token; tokenHash derives its lookup key.
  • The injected now function makes expiry deterministic in tests.

Saved on this device · 0 / 6000 · Do not include passwords or private data.

VERIFY

Acceptance checks

From the folder containing your downloaded files, run:

node checks.mjs ./starter.mjs 2

This runs checks up to this step. Earlier steps must work first. Mark each result only after checking your implementation; the website does not run or grade it.

Record your attempt to enable the checklist and reference comparison.

Compare with the reference

Attempt the step first, then compare decisions and behavior. There can be more than one correct implementation.

EXPLAIN

Your interviewer asks

Why store the hash of a random session token? What happens if the session store leaks?

Say your answer aloud, then record the trade-offs and evidence in your notes above.

LOCAL VOICE REHEARSAL

Rehearse your step walkthrough aloud

Target pacing: 02:00 · Stays in this browser only; never uploaded.

00:00/ 02:00
AlifBay Prep