mirror of
https://github.com/shuaiplus/nodewarden.git
synced 2026-06-20 21:00:41 +00:00
feat: enhance password security with server-side hashing and constant-time comparisons
This commit is contained in:
@@ -24,5 +24,12 @@ export function createRecoveryCode(): string {
|
||||
|
||||
export function recoveryCodeEquals(input: string, storedCode: string | null | undefined): boolean {
|
||||
if (!storedCode) return false;
|
||||
return normalizeRecoveryCode(input) === normalizeRecoveryCode(storedCode);
|
||||
const a = new TextEncoder().encode(normalizeRecoveryCode(input));
|
||||
const b = new TextEncoder().encode(normalizeRecoveryCode(storedCode));
|
||||
if (a.length !== b.length) return false;
|
||||
let diff = 0;
|
||||
for (let i = 0; i < a.length; i++) {
|
||||
diff |= a[i] ^ b[i];
|
||||
}
|
||||
return diff === 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user