Abstract


Example


Nodejs

const { scryptSync, randomBytes } = require('crypto');
 
let user;
function signup(email, password) {
  const salt = randomBytes(16).toString('hex');
  const hash = scryptSync(password, salt, 64).toString('hex');
 
  user = {email, password: `${salt}:${hash}`};
 
  return user;
}
 
function login(email, password) {
  const [salt, hash] = user.password.split(':');
  const verifyHash = scryptSync(password, salt, 64).toString('hex');
 
  return hash === verifyHash;
}
 
 
user = signup('[email protected]', 'password123');
console.log(login('[email protected]', 'password123'))

Terminologies


scrypt