typescripting2
This commit is contained in:
parent
850a3bf4d2
commit
aacc685da1
12 changed files with 381 additions and 128 deletions
21
app/db.ts
Normal file
21
app/db.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
import type {RequestHandler as Middleware} from 'express';
|
||||
|
||||
const sqlite3 = require("sqlite3");
|
||||
const mkdirp = require("mkdirp");
|
||||
const crypto = require("crypto");
|
||||
|
||||
mkdirp.sync("./uploads");
|
||||
mkdirp.sync("./var/db");
|
||||
|
||||
let db = new sqlite3.Database("./var/db/media.db");
|
||||
|
||||
export function createUser(username: string, password: string) {
|
||||
var salt = crypto.randomBytes(16);
|
||||
db.run("INSERT OR IGNORE INTO users (username, hashed_password, salt) VALUES (?, ?, ?)", [
|
||||
username,
|
||||
crypto.pbkdf2Sync(password, salt, 310000, 32, "sha256"),
|
||||
salt
|
||||
]);
|
||||
}
|
||||
|
||||
export default db;
|
Loading…
Add table
Add a link
Reference in a new issue