InterviewHubPRO
Section Overview
Q33

Question 33 of 60

Part 3: Streams, Buffers & Core Modules (21 - 35)

55%
Node.js & Libuv•Part 3: Streams, Buffers & Core Modules (21 - 35)

The `crypto` module: Secure password hashing.

In Simple Words: Use crypto.scrypt() or crypto.pbkdf2() with salt and high work factors for password hashing, or modern native algorithms like Argon2 via dedicated bindings.

javascript
const crypto = require('crypto');

function hashPassword(password) {
  const salt = crypto.randomBytes(16).toString('hex');
  const derivedKey = crypto.scryptSync(password, salt, 64);
  return `${salt}:${derivedKey.toString('hex')}`;
}