feat(auth): admin user updates added
if a password change happens then an email will be sent to the user.
This commit is contained in:
27
frontend/src/utils/passwordGen.ts
Normal file
27
frontend/src/utils/passwordGen.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
export const generatePassword = (length: number) => {
|
||||
const uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
const lowercase = "abcdefghijklmnopqrstuvwxyz";
|
||||
const numbers = "0123456789";
|
||||
const symbols = "!@#$%&()_+-={}:,.<>?/"; // Safe symbol list
|
||||
|
||||
// Ensure the password contains at least one of each required type
|
||||
let password: any = [
|
||||
uppercase[Math.floor(Math.random() * uppercase.length)],
|
||||
lowercase[Math.floor(Math.random() * lowercase.length)],
|
||||
numbers[Math.floor(Math.random() * numbers.length)],
|
||||
symbols[Math.floor(Math.random() * symbols.length)],
|
||||
];
|
||||
|
||||
// Fill the rest of the password with random characters from all sets
|
||||
const allCharacters = uppercase + lowercase;
|
||||
for (let i = password.length; i < length; i++) {
|
||||
password.push(
|
||||
allCharacters[Math.floor(Math.random() * allCharacters.length)]
|
||||
);
|
||||
}
|
||||
|
||||
// Shuffle the password to avoid predictable patterns
|
||||
password = password.sort(() => Math.random() - 0.5).join("");
|
||||
|
||||
return password;
|
||||
};
|
||||
Reference in New Issue
Block a user