-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.js
36 lines (26 loc) · 1014 Bytes
/
helpers.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
29
30
31
32
33
34
35
36
const mysql = require('mysql');
const twinBcrypt = require('twin-bcrypt')
// Old auth: https://pastebin.fi/p/Ohby4U6uhNVQ
exports.auth = async(email, pass) => {
const connection = mysql.createConnection({
host: process.env.MAILCOW_API_BASEURL.replace('https://', ''),
user: 'root',
password: process.env.DBROOT,
database: 'mailcow'
});
connection.connect();
const data = await new Promise((resolve, reject) => {
connection.query('SELECT username, password FROM mailbox WHERE username=?', [email + "@imap.fi"], (err, rows, fields) => {
if (err)
return reject(err);
resolve(rows);
});
});
connection.end();
if (data.length === 0)
return false;
const hash = data[0].password.replace('{BLF-CRYPT}', '')
const authSuccess = twinBcrypt.compareSync(pass, hash)
console.log("Authentication tried for account " + email + " with status: " + authSuccess)
return authSuccess
}