feat: Implement username/password authentication and registration features

This commit is contained in:
beilunyang
2025-01-15 16:00:06 +08:00
parent 969d0ce334
commit 126a4cb948
24 changed files with 2643 additions and 67 deletions
+14 -1
View File
@@ -3,4 +3,17 @@ import { twMerge } from "tailwind-merge"
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
}
export async function hashPassword(password: string): Promise<string> {
const encoder = new TextEncoder()
const salt = process.env.AUTH_SECRET || ''
const data = encoder.encode(password + salt)
const hash = await crypto.subtle.digest('SHA-256', data)
return btoa(String.fromCharCode(...new Uint8Array(hash)))
}
export async function comparePassword(password: string, hashedPassword: string): Promise<boolean> {
const hash = await hashPassword(password)
return hash === hashedPassword
}