Security

Password derivation and verification

Password verification should use a maintained password-hashing implementation that stores a salt and work parameters alongside the derived result. A salt is public per-record randomness, not a secret. Application secrets such as service credentials need a separate restricted storage and rotation process. Never store plaintext or use unsalted SHA-256 for passwords. Do not use the demonstration work factor for production. A salt does not need to be hidden; do not confuse it with an optional separately protected pepper. Do not print real passwords or hashes. Evidence: local teaching fixture, not a production security guarantee. Source: https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html

Formal Syntax & Structure

nodejs syntaxnodejs
scrypt(password, salt, keylen[, options], callback)

Working Example

Example Snippetnodejs
import {scrypt,randomBytes,timingSafeEqual} from 'node:crypto';import {promisify} from 'node:util';const derive = promisify(scrypt);const salt = randomBytes(16);// Lab-only work factor; not a production recommendation.const options = {N:16384,r:8,p:1,maxmem:32*1024*1024};const expected = await derive('fixture-password',salt,32,options);for (const sample of ['fixture-password','different-fixture']) {  const actual = await derive(sample,salt,32,options);  console.log(timingSafeEqual(expected,actual));}
Node.js Reference