2017-08-29 16:05:06 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const Helper = require("../../helper");
|
2018-03-02 18:28:54 +00:00
|
|
|
const colors = require("chalk");
|
2017-08-29 16:05:06 +00:00
|
|
|
|
|
|
|
function localAuth(manager, client, user, password, callback) {
|
|
|
|
// If no user is found, or if the client has not provided a password,
|
|
|
|
// fail the authentication straight away
|
|
|
|
if (!client || !password) {
|
|
|
|
return callback(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If this user has no password set, fail the authentication
|
|
|
|
if (!client.config.password) {
|
|
|
|
log.error(`User ${colors.bold(user)} with no local password set tried to sign in. (Probably a LDAP user)`);
|
|
|
|
return callback(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
Helper.password
|
|
|
|
.compare(password, client.config.password)
|
|
|
|
.then((matching) => {
|
|
|
|
if (matching && Helper.password.requiresUpdate(client.config.password)) {
|
|
|
|
const hash = Helper.password.hash(password);
|
|
|
|
|
|
|
|
client.setPassword(hash, (success) => {
|
|
|
|
if (success) {
|
|
|
|
log.info(`User ${colors.bold(client.name)} logged in and their hashed password has been updated to match new security requirements`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
callback(matching);
|
|
|
|
}).catch((error) => {
|
|
|
|
log.error(`Error while checking users password. Error: ${error}`);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-08-29 17:11:06 +00:00
|
|
|
module.exports = {
|
|
|
|
auth: localAuth,
|
2017-11-15 06:35:15 +00:00
|
|
|
isEnabled: () => true,
|
2017-08-29 17:11:06 +00:00
|
|
|
};
|
|
|
|
|