-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
28 lines (24 loc) · 891 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const {sha512crypt} = require('sha512crypt-node');
exports.hook_capabilities = function (next, connection) {
// Don't offer AUTH capabilities by default unless session is encrypted
if (connection.tls.enabled) {
const methods = ['PLAIN', 'LOGIN'];
connection.capabilities.push(`AUTH ${methods.join(' ')}`);
connection.notes.allowed_auth_methods = methods;
}
next();
}
exports.register = function () {
this.inherits('auth/auth_base');
this.load_auth_enc_file_ini();
}
exports.load_auth_enc_file_ini = function () {
this.cfg = this.config.get('auth_enc_file.ini', this.load_auth_enc_file_ini);
}
exports.check_plain_passwd = function (connection, user, passwd, cb) {
if (this.cfg.users[user]) {
const [method, id, salt, hash] = this.cfg.users[user].split('$');
return cb(sha512crypt(passwd, salt) === `$${id}$${salt}$${hash}`);
}
return cb(false);
}