Get your own Node server
const crypto = require('crypto');

// Secure password hashing with PBKDF2
function hashPasswordSecure(password, salt, iterations = 100000) {
  return new Promise((resolve, reject) => {
    crypto.pbkdf2(
      password,
      salt,
      iterations,
      64,      // Key length in bytes
      'sha512', // Hash function
      (err, derivedKey) => {
        if (err) reject(err);
        resolve(derivedKey.toString('hex'));
      }
    );
  });
}

// Generate a random salt
function generateSalt() {
  return crypto.randomBytes(16).toString('hex');
}

// Example usage
async function example() {
  try {
    const password = 'mySecurePassword123';
    
    // For a new user, generate a salt and hash the password
    const salt = generateSalt();
    const iterations = 100000; // Higher is more secure but slower
    
    console.log('Password:', password);
    console.log('Salt:', salt);
    console.log('Iterations:', iterations);
    
    const hashedPassword = await hashPasswordSecure(password, salt, iterations);
    console.log('Hashed Password:', hashedPassword);
    
    // To verify a password
    const verifyCorrect = await hashPasswordSecure(password, salt, iterations) === hashedPassword;
    console.log('Verification with correct password:', verifyCorrect);
    
    const verifyWrong = await hashPasswordSecure('wrongPassword', salt, iterations) === hashedPassword;
    console.log('Verification with incorrect password:', verifyWrong);
    
  } catch (error) {
    console.error('Error:', error.message);
  }
}

// Run the example
example();

              
Password: mySecurePassword123
Salt: 1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7
Iterations: 100000
Hashed Password: 5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1a2b31a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1a2b3
Verification with correct password: true
Verification with incorrect password: false