feat: add auth utilities (Argon2, session tokens)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-26 11:54:35 -05:00
co-authored by Claude Opus 4.6
parent fdc27584c9
commit 86c1389d67
2 changed files with 51 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
import { hash, verify } from '@node-rs/argon2';
import crypto from 'crypto';
export async function hashPassword(password: string): Promise<string> {
return hash(password);
}
export async function verifyPassword(hashedPassword: string, password: string): Promise<boolean> {
try {
return await verify(hashedPassword, password);
} catch {
return false;
}
}
export function generateSessionToken(): string {
return crypto.randomBytes(32).toString('hex');
}
export function hashSessionToken(token: string): string {
return crypto.createHash('sha256').update(token).digest('hex');
}