Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Commit

Permalink
hash password with pbkdf2
Browse files Browse the repository at this point in the history
  • Loading branch information
davychiu committed Dec 4, 2013
1 parent dbe7213 commit ebddcd3
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions app/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ UserSchema.methods = {
* @api public
*/
makeSalt: function() {
return Math.round((new Date().valueOf() * Math.random())) + '';
return crypto.randomBytes(16).toString('base64');
},

/**
Expand All @@ -117,8 +117,9 @@ UserSchema.methods = {
*/
encryptPassword: function(password) {
if (!password) return '';
return crypto.createHmac('sha1', this.salt).update(password).digest('hex');
salt = new Buffer(this.salt, 'base64');
return crypto.pbkdf2Sync(password, salt, 10000, 64).toString('base64');
}
};

mongoose.model('User', UserSchema);
mongoose.model('User', UserSchema);

0 comments on commit ebddcd3

Please sign in to comment.