我得到了错误“返回绑定”.PBKDF2(密码、盐、迭代、keylen、回调);^ TypeError: Not a bu
I'm getting the error "return binding.PBKDF2(password, salt, iterations, keylen, callback); ^ TypeError: Not a buffer"
查看下面的完整错误代码:
<>之前crypto.js: 601返回绑定。PBKDF2(密码、盐、迭代、keylen、回调);^类型错误:不是缓冲区在pbkdf2 (crypto.js:601:20)在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)在查询。(/用户/markie13/文档/说/meanPassport/config/策略/local.js: 19:14)。在/用户/markie13/文件/说/meanPassport/node_modules/猫鼬/node_modules/kareem/index.js: 177:19在/用户/markie13/文件/说/meanPassport/node_modules/猫鼬/node_modules/kareem/index.js: 109:16在过程。_tickCallback (node . js: 442:13)之前我正在研读Amos Haviv的书《MEAN Stack Development》,读到第6章了——如果有人关心的话。
下面是抛出错误的代码(查看行号的注释):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
};
所以,事实证明,我是用一个非散列字符串填充mongodb数据库的密码。
当我用数据库中的散列密码登录时,它工作得很好。
现在我需要学习错误检查…
相关文章:
- AngularJS:我可以跳过函数参数回调吗
- 要求未定义JS回调参数
- MeteorJS:在带有回调的vzaar api上正确使用wrapAsync
- 自引用回调
- 测试Angular Service解决错误回调中的promise
- 如何将一个JavaScript函数回调为多个函数
- JavaScript回调函数
- 用于回调的javascript参数
- 将json回调数据转换为日期
- 承诺在非节点式回调上使用Bluebird
- 如何在回调函数中执行流
- 回调函数中传递参数的困难(Google Map API Markers)
- Soundcloud Javascript SDK 3.0-回调无法读取属性'connectCallback
- 如何使用jqueryAJAX从页面中回调多个变量
- jquery Onclick函数带有导致双击的回调排序函数
- Javascript点击事件回调不起作用
- 一旦加载并渲染了角度引导typeahead,就使用回调
- 成功回调永远不会被JSONP请求调用
- 如何让程序员在javascript中实现正确的回调
- 我得到了错误“返回绑定”.PBKDF2(密码、盐、迭代、keylen、回调);^ TypeError: Not a bu