[英]'Incorrect arguments' thrown by bcrypt-nodejs - Passport
I have a log in system set up for my Node.js app.我为我的 Node.js 应用程序设置了登录系统。 Recently I made a change to my user model (CoffeeScript):
最近我对我的用户模型(CoffeeScript)进行了更改:
password: String
to到
password:
type: String
select: false
My function to compare password hashes with bcrypt is as follows:我将密码哈希与 bcrypt 进行比较的函数如下:
userSchema.methods.validPassword = (password) ->
bcrypt.compareSync password, @local.password
Now whenever I run the above function this error is thrown现在每当我运行上述函数时都会抛出这个错误
Incorrect arguments
Anyone have any idea why this would be thrown after I add "select: false" to my user model?任何人都知道为什么在我将“select:false”添加到我的用户模型后会抛出这个问题?
This is thrown if either password or @local.password is not a string.如果 password 或 @local.password 不是字符串,则会抛出此错误。 It just happened to me as I was trying to call the instance method on an instance that was not including @local.password in the loaded attributes.
它只是发生在我身上,因为我试图在加载的属性中不包含 @local.password 的实例上调用实例方法。
userSchema.methods.validPassword = (password) ->
bcrypt.compareSync password, @local.password
Assuming this is in a class, you'll need =>
rather than ->
in order for @local
to work.假设这是在一个类中,您将需要
=>
而不是->
以便@local
工作。
Log the values of both the saved password and the incoming password.记录保存的密码和传入密码的值。 My bet is that one of them is undefined.
我敢打赌,其中之一是未定义的。
检查密码值是否正在填充。设置选择 false 将不会检索密码值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.