相关疑难解决方法(0)

nodejs中的SALT和HASH密码w/crypto

我试图找出如何使用crypto模块在nodejs中加密和散列密码.我可以创建哈希密码来做到这一点:

UserSchema.pre('save', function(next) {
  var user = this;

  var salt = crypto.randomBytes(128).toString('base64');
  crypto.pbkdf2(user.password, salt, 10000, 512, function(err, derivedKey) {
    user.password = derivedKey;
    next();
  });
});
Run Code Online (Sandbox Code Playgroud)

但是我对如何验证密码感到困惑.

UserSchema.methods.validPassword = function(password) {    
  // need to salt and hash this password I think to compare
  // how to I get the salt?
}
Run Code Online (Sandbox Code Playgroud)

node.js node-crypto

30
推荐指数
6
解决办法
5万
查看次数

标签 统计

node-crypto ×1

node.js ×1