-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb.js
More file actions
37 lines (32 loc) · 801 Bytes
/
db.js
File metadata and controls
37 lines (32 loc) · 801 Bytes
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
37
import mysql from "mysql";
import crypto from "crypto";
import config from "./config.js";
var pool = mysql.createPool({
...config.db,
supportBigNumbers: true,
bigNumberStrings: true
});
pool.on('error', (err) => {
console.error(err);
});
/**
* @param {string} query
* @returns {Promise<any[]>}
*/
export function asyncQuery(query) {
return new Promise((resolve, reject) => {
pool.query(query, (error, result, fields) => {
if (error) {
reject(error);
} else {
resolve(result);
}
})
});
}
export function genSalt() {
return crypto.randomBytes(16);
}
export function hashPassword(password, salt) {
return crypto.pbkdf2Sync(Buffer.from(password), salt, 10000, 256 / 8, "sha1");
}