, . , , . , , , - ( ). . "salt" ?
var salt = crypto.randomBytes(128).toString('base64');
var hashPwd = function hashPwd(salt, pwd) {
var hmac = crypto.createHmac('sha256', salt);
return hmac.update(pwd).digest('hex');
};
var passHash = hashPwd(salt,data.Password);
console.log('the password is', user.PassHash === passHash);
, ( salt var , http-).
(imo) - , bcrypt. , , , . , , , .
npm install bcrypt
...
var bcrypt = require('bcrypt');
var hash = bcrypt.hashSync("my password");
bcrypt.compareSync("my password", hash); // true
bcrypt.compareSync("not my password", hash); // false
compareAsync . . : https://www.npmjs.com/package/bcrypt-nodejs