mirror of
https://github.com/beilunyang/moemail.git
synced 2026-09-04 23:06:37 +08:00
feat: Implement username/password authentication and registration features
This commit is contained in:
+14
-1
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user