feat: add auth utilities (Argon2, session tokens)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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');
|
||||
}
|
||||
Reference in New Issue
Block a user