mirror of
https://github.com/beilunyang/moemail.git
synced 2025-12-24 11:30:51 +08:00
19 lines
667 B
TypeScript
19 lines
667 B
TypeScript
import { type ClassValue, clsx } from "clsx"
|
|
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
|
|
} |