allow optional length parameter for Froxlor.generatePassword API command

Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
Michael Kaufmann
2022-10-17 17:26:13 +02:00
parent 2987ae5a05
commit 28f6d59336
2 changed files with 9 additions and 3 deletions

View File

@@ -36,13 +36,15 @@ class Crypt
/**
* Generates a random password
*/
public static function generatePassword()
public static function generatePassword(int $length = 0)
{
$alpha_lower = 'abcdefghijklmnopqrstuvwxyz';
$alpha_upper = strtoupper($alpha_lower);
$numeric = '0123456789';
$special = Settings::Get('panel.password_special_char');
$length = Settings::Get('panel.password_min_length') > 3 ? Settings::Get('panel.password_min_length') : 10;
if (empty($length)) {
$length = Settings::Get('panel.password_min_length') > 3 ? Settings::Get('panel.password_min_length') : $length;
}
$pw = self::specialShuffle($alpha_lower);
$n = floor(($length) / 4);