feat: enhance login handling by introducing local hash derivation and updating session management

This commit is contained in:
shuaiplus
2026-03-17 08:50:47 +08:00
parent 0ba85229a9
commit 3791f89a5c
4 changed files with 118 additions and 19 deletions
+12
View File
@@ -109,6 +109,18 @@ export async function deriveLoginHash(email: string, password: string, fallbackI
return { hash: bytesToBase64(hash), masterKey, kdfIterations: iterations };
}
export async function deriveLoginHashLocally(
email: string,
password: string,
fallbackIterations: number
): Promise<PreloginResult> {
const normalizedEmail = String(email || '').trim().toLowerCase();
const iterations = Number(fallbackIterations || 600000);
const masterKey = await pbkdf2(password, normalizedEmail, iterations, 32);
const hash = await pbkdf2(masterKey, password, 1, 32);
return { hash: bytesToBase64(hash), masterKey, kdfIterations: iterations };
}
export async function getPreloginKdfConfig(email: string, fallbackIterations: number): Promise<PreloginKdfConfig> {
const normalized = String(email || '').trim().toLowerCase();
if (!normalized) throw new Error('Email is required');