File size: 511 Bytes
b80fc11 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | 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 };
};
|