-
Notifications
You must be signed in to change notification settings - Fork 69
Open
Description
I encounter an issue when using CompareSync in model
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var bcrypt = require('bcrypt-nodejs');
// create a schema
var userSchema = new Schema({
username: { type: String, required: true, unique: true },
password: {type: String, required:true}
});
userSchema.methods.generateHash = function(password) {
return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null);
};
// checking if password is valid
userSchema.methods.validPassword = function(password) {
console.log("Normal call 7 " + password + "\t" + this.password); //todo debug line
var result = bcrypt.compareSync(password, this.password);
console.log("Normal 8" + result);
return bcrypt.compareSync(password, this.password);
};
var Users = mongoose.model('Users', userSchema);
module.exports = Users;
The result is as follows
Normal call 7 password1234 password1234
events.js:74
throw TypeError('Uncaught, unspecified "error" event.');
^
TypeError: Uncaught, unspecified "error" event.
at TypeError (<anonymous>)
at Function.EventEmitter.emit (events.js:74:15)
at Query.<anonymous> (<project dir>/node_modules/mongoose/lib/model.js:3326:13)
at <project dir>/node_modules/mongoose/node_modules/kareem/index.js:259:21
at <project dir>/node_modules/mongoose/node_modules/kareem/index.js:127:16
at process._tickCallback (node.js:415:13)
As you can see, the program is normal before calling compareSync, and the Strings to compare are quite reasonable, and it throws an exception
Metadata
Metadata
Assignees
Labels
No labels