hash password with pbkdf2

This commit is contained in:
Davy Chiu
2013-12-04 05:20:48 -08:00
parent dbe7213f77
commit ebddcd319a

View File

@@ -105,7 +105,7 @@ UserSchema.methods = {
* @api public
*/
makeSalt: function() {
return Math.round((new Date().valueOf() * Math.random())) + '';
return crypto.randomBytes(16).toString('base64');
},
/**
@@ -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);