mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
21 lines
511 B
TypeScript
21 lines
511 B
TypeScript
import bcrypt from "bcrypt";
|
|
|
|
export const generateRandomPassword = async () => {
|
|
const passwordLength = 16;
|
|
|
|
const characters =
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
|
|
let randomPassword = "";
|
|
for (let i = 0; i < passwordLength; i++) {
|
|
randomPassword += characters.charAt(
|
|
Math.floor(Math.random() * characters.length),
|
|
);
|
|
}
|
|
|
|
const saltRounds = 10;
|
|
|
|
const hashedPassword = await bcrypt.hash(randomPassword, saltRounds);
|
|
return { randomPassword, hashedPassword };
|
|
};
|