mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-07-21 07:51:24 +02:00
Fixed password hashing in general
This commit is contained in:
@@ -129,56 +129,50 @@ exports.changePassword = function(req, res, next) {
|
||||
var passwordDetails = req.body;
|
||||
var message = null;
|
||||
|
||||
if (passwordDetails.currentPassword) {
|
||||
if (req.user) {
|
||||
User.findById(req.user.id, function(err, user) {
|
||||
if (!err && user) {
|
||||
if (user.authenticate(passwordDetails.currentPassword)) {
|
||||
if (passwordDetails.newPassword === passwordDetails.verifyPassword) {
|
||||
user.password = passwordDetails.newPassword;
|
||||
if (req.user) {
|
||||
User.findById(req.user.id, function(err, user) {
|
||||
if (!err && user) {
|
||||
if (user.authenticate(passwordDetails.currentPassword)) {
|
||||
if (passwordDetails.newPassword === passwordDetails.verifyPassword) {
|
||||
user.password = passwordDetails.newPassword;
|
||||
|
||||
user.save(function(err) {
|
||||
if (err) {
|
||||
return res.send(400, {
|
||||
message: getErrorMessage(err)
|
||||
});
|
||||
} else {
|
||||
req.login(user, function(err) {
|
||||
if (err) {
|
||||
res.send(400, err);
|
||||
} else {
|
||||
res.send({
|
||||
message: 'Password changed successfully'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
user.save(function(err) {
|
||||
if (err) {
|
||||
return res.send(400, {
|
||||
message: getErrorMessage(err)
|
||||
});
|
||||
} else {
|
||||
req.login(user, function(err) {
|
||||
if (err) {
|
||||
res.send(400, err);
|
||||
} else {
|
||||
res.send({
|
||||
message: 'Password changed successfully'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
res.send(400, {
|
||||
message: 'Passwords do not match'
|
||||
});
|
||||
}
|
||||
} else {
|
||||
res.send(400, {
|
||||
message: 'Current password is incorrect'
|
||||
message: 'Passwords do not match'
|
||||
});
|
||||
}
|
||||
} else {
|
||||
res.send(400, {
|
||||
message: 'User is not found'
|
||||
message: 'Current password is incorrect'
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
res.send(400, {
|
||||
message: 'User is not signed in'
|
||||
});
|
||||
}
|
||||
} else {
|
||||
res.send(400, {
|
||||
message: 'User is not found'
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
res.send(400, {
|
||||
message: 'Please fill current password'
|
||||
message: 'User is not signed in'
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -92,7 +92,11 @@ UserSchema.pre('save', function(next) {
|
||||
* Create instance method for hashing a password
|
||||
*/
|
||||
UserSchema.methods.hashPassword = function(password) {
|
||||
return crypto.pbkdf2Sync(password, this.salt, 10000, 64).toString('base64');
|
||||
if (password) {
|
||||
return crypto.pbkdf2Sync(password, this.salt, 10000, 64).toString('base64');
|
||||
} else {
|
||||
return password;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user