Skip to content

Commit

Permalink
add direct check against password hash for hashed passwords
Browse files Browse the repository at this point in the history
  • Loading branch information
hubermat committed Apr 16, 2020
1 parent 457c0cd commit dba5181
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions ctldap.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,21 @@ Object.keys(config.sites).map(function(sitename, index) {
site.loginErrorCount = 0;
}
}
var hash = site.ldap_password.replace(/^\$2y(.+)$/i, '$2a$1');
bcrypt.compare(password, hash, function(err, valid) {
if (!valid) {
site.loginErrorCount += 1;
if (site.loginErrorCount > 5) {
site.loginBlockedDate = new Date();
var directCheckValid = (password === site.ldap_password);
if (directCheckValid) {
callback(true);
} else {
var hash = site.ldap_password.replace(/^\$2y(.+)$/i, '$2a$1');
bcrypt.compare(password, hash, function (err, valid) {
if (!valid) {
site.loginErrorCount += 1;
if (site.loginErrorCount > 5) {
site.loginBlockedDate = new Date();
}
}
}
callback(valid);
});
callback(valid);
});
}
}
} else {
site.checkPassword = function (password, callback) {
Expand Down

0 comments on commit dba5181

Please sign in to comment.