This commit is contained in:
Louis Lam
2023-11-07 20:47:16 +08:00
parent 7a63d59ef8
commit 015e4c21f9
12 changed files with 374 additions and 246 deletions

View File

@@ -3,6 +3,8 @@ import { Terminal } from "./terminal";
import { randomBytes } from "crypto";
import { log } from "./log";
import { ERROR_TYPE_VALIDATION } from "./util-common";
import { R } from "redbean-node";
import { verifyPassword } from "./password-hash";
export interface DockgeSocket extends Socket {
userID: number;
@@ -57,3 +59,19 @@ export function callbackError(error : unknown, callback : unknown) {
log.debug("console", "Unknown error: " + error);
}
}
export async function doubleCheckPassword(socket : DockgeSocket, currentPassword : unknown) {
if (typeof currentPassword !== "string") {
throw new Error("Wrong data type?");
}
let user = await R.findOne("user", " id = ? AND active = 1 ", [
socket.userID,
]);
if (!user || !verifyPassword(currentPassword, user.password)) {
throw new Error("Incorrect current password");
}
return user;
}