mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-12-23 17:00:24 +01:00
change isPasswordCorrect to return false if user does not have password
This commit is contained in:
@@ -37,6 +37,12 @@ SocketUser.deleteAccount = function (socket, data, callback) {
|
|||||||
|
|
||||||
async.waterfall([
|
async.waterfall([
|
||||||
function (next) {
|
function (next) {
|
||||||
|
user.hasPassword(socket.uid, next);
|
||||||
|
},
|
||||||
|
function (hasPassword, next) {
|
||||||
|
if (!hasPassword) {
|
||||||
|
return next();
|
||||||
|
}
|
||||||
user.isPasswordCorrect(socket.uid, data.password, socket.ip, function (err, ok) {
|
user.isPasswordCorrect(socket.uid, data.password, socket.ip, function (err, ok) {
|
||||||
next(err || (!ok ? new Error('[[error:invalid-password]]') : undefined));
|
next(err || (!ok ? new Error('[[error:invalid-password]]') : undefined));
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -24,9 +24,7 @@ module.exports = function (User) {
|
|||||||
},
|
},
|
||||||
function (_hashedPassword, next) {
|
function (_hashedPassword, next) {
|
||||||
hashedPassword = _hashedPassword;
|
hashedPassword = _hashedPassword;
|
||||||
if (uid && !hashedPassword) {
|
if (!hashedPassword) {
|
||||||
return callback(null, true);
|
|
||||||
} else if (!hashedPassword) {
|
|
||||||
// Non-existant user, submit fake hash for comparison
|
// Non-existant user, submit fake hash for comparison
|
||||||
hashedPassword = '';
|
hashedPassword = '';
|
||||||
}
|
}
|
||||||
@@ -37,17 +35,13 @@ module.exports = function (User) {
|
|||||||
function (next) {
|
function (next) {
|
||||||
Password.compare(password, hashedPassword, next);
|
Password.compare(password, hashedPassword, next);
|
||||||
},
|
},
|
||||||
], function (err, ok) {
|
function (ok, next) {
|
||||||
if (err) {
|
if (ok) {
|
||||||
return callback(err);
|
User.auth.clearLoginAttempts(uid);
|
||||||
}
|
}
|
||||||
|
next(null, ok);
|
||||||
if (ok) {
|
},
|
||||||
User.auth.clearLoginAttempts(uid);
|
], callback);
|
||||||
}
|
|
||||||
|
|
||||||
callback(null, ok);
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
User.hasPassword = function (uid, callback) {
|
User.hasPassword = function (uid, callback) {
|
||||||
|
|||||||
@@ -303,6 +303,19 @@ describe('authentication', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should fail to login if user does not have password field in db', function (done) {
|
||||||
|
user.create({ username: 'hasnopassword', email: 'no@pass.org' }, function (err, uid) {
|
||||||
|
assert.ifError(err);
|
||||||
|
loginUser('hasnopassword', 'doesntmatter', function (err, response, body) {
|
||||||
|
assert.ifError(err);
|
||||||
|
console.log(response.statusCode, body);
|
||||||
|
assert.equal(response.statusCode, 403);
|
||||||
|
assert.equal(body, '[[error:invalid-login-credentials]]');
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('should fail to login if password is longer than 4096', function (done) {
|
it('should fail to login if password is longer than 4096', function (done) {
|
||||||
var longPassword;
|
var longPassword;
|
||||||
for (var i = 0; i < 5000; i++) {
|
for (var i = 0; i < 5000; i++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user