mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-05-07 17:26:25 +02:00
Merge pull request #253 from rmuch/fix-salt-encoding
Correctly encode and decode password salt
This commit is contained in:
@@ -96,7 +96,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);
|
||||
}
|
||||
|
||||
@@ -108,7 +108,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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user