mirror of
https://github.com/pterodactyl/panel.git
synced 2026-12-04 13:25:47 -05:00
Added a secure password generator to admin customer user manager and
user account manager as shown below:
## Extra Details:
- Added a reusable password field component with:
- 17-character random password generation
- Uppercase and lowercase letters
- Numbers
- Symbols
- Password visibility toggle button
- Clipboard copy button after the new password is generated
- Integrated the feature into:
- Admin customer user creation area
- Admin customer user editing area
- Customer User account settings
<img width="430" height="466"
alt="{2DD29137-22E3-4446-8DB5-4F37AD322DF2}"
src="https://github.com/user-attachments/assets/03ef614a-3f4e-4ba6-bdbc-1a99e07959c6"
/>
<img width="427" height="120"
alt="{A3073146-78CD-459C-A837-EBAB72E8ABA4}"
src="https://github.com/user-attachments/assets/5c9cf583-4941-4c0d-893a-fe85c4e46f3c"
/>
<img width="413" height="142"
alt="{2DB05B11-7781-403D-ABC1-CEF11D31E1E8}"
src="https://github.com/user-attachments/assets/0131b770-9120-4f14-8bbd-8dfc374e6263"
/>
<img width="457" height="249"
alt="{8AA4DACE-CBA4-41F1-A5FA-F1EEB3B72632}"
src="https://github.com/user-attachments/assets/2f3004fe-74b2-4060-82eb-ac3f12d5f00f"
/>
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
const passwordCharacterSets = {
|
|
uppercase: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
|
lowercase: 'abcdefghijklmnopqrstuvwxyz',
|
|
numbers: '0123456789',
|
|
symbols: '!@#$%^&*()_+=-[]{}',
|
|
} as const;
|
|
|
|
const secureRandomIndex = (length: number): number => {
|
|
if (length < 1) {
|
|
return 0;
|
|
}
|
|
|
|
const limit = 0x100000000 - (0x100000000 % length);
|
|
const values = new Uint32Array(1);
|
|
let value: number;
|
|
|
|
do {
|
|
crypto.getRandomValues(values);
|
|
value = values[0];
|
|
} while (value >= limit);
|
|
|
|
return value % length;
|
|
};
|
|
|
|
const randomCharacter = (characters: string): string => characters[secureRandomIndex(characters.length)];
|
|
|
|
/**
|
|
* Generates a secure password using the defined random character sets.
|
|
*
|
|
* @param length The requested password length.
|
|
*/
|
|
export const generateSecurePassword = (length = 17): string => {
|
|
const characterSets = Object.values(passwordCharacterSets);
|
|
const allCharacters = characterSets.join('');
|
|
const password = characterSets.map(randomCharacter);
|
|
|
|
while (password.length < length) {
|
|
password.push(randomCharacter(allCharacters));
|
|
}
|
|
|
|
for (let index = password.length - 1; index > 0; index--) {
|
|
const swapIndex = secureRandomIndex(index + 1);
|
|
[password[index], password[swapIndex]] = [password[swapIndex], password[index]];
|
|
}
|
|
|
|
return password.join('');
|
|
};
|