Added Backend
This commit is contained in:
15
backend/src/utils/password.ts
Normal file
15
backend/src/utils/password.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user