Instructor walkthrough and answer key
- In the student app folder run
node server.mjs. Open http://127.0.0.1:3000. - Register
Campus-demo-42!. Correct password gives 200;Wrong-demo-42!gives 401. - Inspect and decode. The Base64 text decodes to the exact fictional password.
- Register the same password again. The value is identical because encoding is deterministic.
- Stop the server. Running
node checks.mjsgives five passes, two failures, and exit code 1. This is the intentional baseline. - In
password-store.mjs, change the storage line toreturn await hashPassword(password);and the checking line toreturn await verifyPassword(password, stored);. - Save and restart with
node server.mjs. Refresh and register again. Storage now startsscrypt$131072$8$1$; decode returnsrecoveredPassword: null. - Correct/wrong checks remain 200/401. Registering the same password again yields a different record; correct login still succeeds.
- Stop and run
node checks.mjs: all seven pass, exit code 0.
Expected explanations
- A working login checks functionality, not how stored credentials survive disclosure.
- Base64 is a reversible representation with no secret key. Encryption is reversible with a key. Password hashing supports verification without a decoding operation.
- Each registration generates a random 16-byte salt. The record stores salt, parameters and hash. A salt is public; it is not a secret encryption key.
- Verification derives a result from the submitted password using the stored salt and settings, then compares fixed-length bytes. Creating a new salted hash and comparing complete strings is wrong.
- A failed decoding demonstration is narrow evidence. Hashes still allow offline guessing; scrypt raises its cost. Weak passwords are not made unguessable.
- Additional protections might include HTTPS, appropriate rate limiting, MFA or secure session management. Any one relevant answer with a short explanation is sufficient.
Common student mistakes
Changing only registration makes verification incompatible. Changing only checking rejects existing Base64 records. Saving without restarting runs the old module. Restarting without re-registration leaves no account. Hiding inspector text does not change actual storage.
The checks invoke a separate fresh server. They do not test the student's browser account. When guiding students, use the worksheet edits on a clean exported copy, not the supplied solution, so the starting experience stays reproducible.