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

Commit

Permalink
Merge pull request #376 from rmuch/fix-salt-encoding-merge-0.4.0
Browse files Browse the repository at this point in the history
Correctly encode and decode password salt (0.4.0)
  • Loading branch information
lirantal committed Mar 8, 2015
2 parents 69b0588 + 08f1750 commit 61f1a22
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions modules/users/server/models/user.server.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ var UserSchema = new Schema({
*/
UserSchema.pre('save', function(next) {
if (this.password && this.password.length > 6) {
this.salt = new Buffer(crypto.randomBytes(16).toString('base64'), 'base64');
this.salt = crypto.randomBytes(16).toString('base64');
this.password = this.hashPassword(this.password);
}

Expand All @@ -112,7 +112,7 @@ UserSchema.pre('save', function(next) {
*/
UserSchema.methods.hashPassword = function(password) {
if (this.salt && password) {
return crypto.pbkdf2Sync(password, this.salt, 10000, 64).toString('base64');
return crypto.pbkdf2Sync(password, new Buffer(this.salt, 'base64'), 10000, 64).toString('base64');
} else {
return password;
}
Expand Down

0 comments on commit 61f1a22

Please sign in to comment.