File size: 563 Bytes
4e23b01 | 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 | import bcrypt from 'bcryptjs';
const { compare, hash } = bcrypt;
const BCRYPT_COST = 12;
export async function resolvePasswordHash(
env: NodeJS.ProcessEnv = process.env,
): Promise<string | undefined> {
const plaintext = env['KIMI_CODE_PASSWORD'];
if (!plaintext) {
return undefined;
}
return hash(plaintext, BCRYPT_COST);
}
export async function verifyPassword(
candidate: string,
passwordHash: string | undefined,
): Promise<boolean> {
if (passwordHash === undefined) {
return false;
}
return compare(candidate, passwordHash);
}
|