请参阅下面的完整错误代码:
crypto.js:601 return binding.PBKDF2(password, salt, iterations, keylen, callback); ^ TypeError: Not a buffer at pbkdf2 (crypto.js:601:20) at Object.exports.pbkdf2Sync (crypto.js:592:10) at model.UserSchema.methods.hashPassword (/Users/markie13/documents/mean/meanPassport/app/models/user.server.model.js:59:16) at model.UserSchema.methods.authenticate (/Users/markie13/documents/mean/meanPassport/app/models/user.server.model.js:63:32) at Query. (/Users/markie13/documents/mean/meanPassport/config/strategies/local.js:19:14) at /Users/markie13/documents/mean/meanPassport/node_modules/mongoose/node_modules/kareem/index.js:177:19 at /Users/markie13/documents/mean/meanPassport/node_modules/mongoose/node_modules/kareem/index.js:109:16 at process._tickCallback (node.js:442:13)
I'm working the Amos Haviv's book MEAN Stack Development and am in chapter 6 - if anyone cares.
Here is the code that is throwing the error (see comments for line numbers):
UserSchema.pre('save', function (next) {
if (this.password) {
this.salt = new Buffer(crypto.randomBytes(16).toString('base64'), 'base64');
this.password = this.hashPassword(this.password);
}
next();
});
UserSchema.methods.hashPassword = function (password) {
return crypto.pbkdf2Sync(password, this.salt, 10000, 64).toString('base64');//line 59
};
UserSchema.methods.authenticate = function (password) {
return this.password === this.hashPassword(password);//line 63
};
最佳答案
所以,事实证明我正在使用非散列密码字符串填充 Mongo 数据库。
当我使用数据库中的散列密码登录后,它工作正常。
现在我需要学习错误检查...
关于javascript - 我收到错误 "return binding.PBKDF2(password, salt, iterations, keylen, callback); ^ TypeError: Not a buffer",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32960687/