From 09f1eab636ea8cda7b795ec63df2b2e79a7dfeac Mon Sep 17 00:00:00 2001 From: Amos Haviv Date: Wed, 16 Apr 2014 12:53:22 +0300 Subject: [PATCH] Adding the salt part to the hashPassword FN --- app/models/user.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/models/user.js b/app/models/user.js index 0bf0c492..b5cfdff3 100755 --- a/app/models/user.js +++ b/app/models/user.js @@ -93,7 +93,7 @@ UserSchema.pre('save', function(next) { * Create instance method for hashing a password */ UserSchema.methods.hashPassword = function(password) { - if (password) { + if (this.salt && password) { return crypto.pbkdf2Sync(password, this.salt, 10000, 64).toString('base64'); } else { return password; @@ -104,9 +104,6 @@ UserSchema.methods.hashPassword = function(password) { * Create instance method for authenticating user */ UserSchema.methods.authenticate = function(password) { - if (!this.password || !this.salt) { - return false; - } return this.password === this.hashPassword(password); };