From a92f67f2e7e59b92349d0c5c3da885ec0a718372 Mon Sep 17 00:00:00 2001 From: Chris Sevilleja Date: Sat, 7 Dec 2013 07:54:04 -0800 Subject: [PATCH 1/3] Update user.js --- app/models/user.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/user.js b/app/models/user.js index 4860387..b7cc5b8 100644 --- a/app/models/user.js +++ b/app/models/user.js @@ -42,7 +42,7 @@ userSchema.methods.hashPassword = function(password) { var user = this; // hash the password - bcrypt.hash(user.local.password, null, null, function(err, hash) { + bcrypt.hash(password, null, null, function(err, hash) { if (err) return next(err); From 46991822fa471f17c392ba8cb82d74ffa7e1ed01 Mon Sep 17 00:00:00 2001 From: Chris Sevilleja Date: Thu, 2 Jan 2014 09:57:37 -0800 Subject: [PATCH 2/3] Update user.js --- app/models/user.js | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/app/models/user.js b/app/models/user.js index b7cc5b8..dc7c764 100644 --- a/app/models/user.js +++ b/app/models/user.js @@ -31,24 +31,15 @@ var userSchema = mongoose.Schema({ }); -// checking if password is valid using bcrypt -userSchema.methods.validPassword = function(password) { - return bcrypt.compareSync(password, this.local.password); +// methods ====================== +// generating a hash +userSchema.methods.generateHash = function(password) { + return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null); }; - -// this method hashes the password and sets the users password -userSchema.methods.hashPassword = function(password) { - var user = this; - - // hash the password - bcrypt.hash(password, null, null, function(err, hash) { - if (err) - return next(err); - - user.local.password = hash; - }); - +// checking if password is valid +userSchema.methods.validPassword = function(password) { + return bcrypt.compareSync(password, this.local.password); }; // create the model for users and expose it to our app From d3264d30a9b1ff9cd16bdaad1e0c1fb824587d29 Mon Sep 17 00:00:00 2001 From: Chris Sevilleja Date: Thu, 2 Jan 2014 09:58:04 -0800 Subject: [PATCH 3/3] Update passport.js --- config/passport.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/passport.js b/config/passport.js index 14d7c10..852a331 100644 --- a/config/passport.js +++ b/config/passport.js @@ -59,7 +59,7 @@ module.exports = function(passport) { // set the user's local credentials newUser.local.email = email; - newUser.hashPassword(password); // use the generateHash function in our user model + newUser.local.password = newUser.generateHash(password); // use the generateHash function in our user model // save the user newUser.save(function(err) {