15 lines
491 B
TypeScript
15 lines
491 B
TypeScript
import bcrypt from "bcrypt"
|
|
|
|
export function generateRandomPassword(length = 12): string {
|
|
const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*"
|
|
let password = ""
|
|
for (let i = 0; i < length; i++) {
|
|
password += chars.charAt(Math.floor(Math.random() * chars.length))
|
|
}
|
|
return password
|
|
}
|
|
|
|
export async function hashPassword(password: string): Promise<string> {
|
|
const saltRounds = 10
|
|
return bcrypt.hash(password, saltRounds)
|
|
} |