// Import 'crypto' module
const crypto = require('crypto');
// Example password
const password = 'mypassword';
// Create SHA-256 hash of the password
const hash = crypto.createHash('sha256').update(password).digest('hex');
// Log the generated hash
console.log('Hash:', hash);
code
Hashing Password with SHA-256 using 'crypto' module
This Node.js code uses the 'crypto' module to create a SHA-256 hash of a password ('mypassword') and logs the resulting hash. The comments provide explanations for each part of the code.
Node.js
Hashing
SHA-256
crypto module
Password Security