allow optional length parameter for Froxlor.generatePassword API command
Signed-off-by: Michael Kaufmann <d00p@froxlor.org>
This commit is contained in:
@@ -254,12 +254,16 @@ class Froxlor extends ApiCommand
|
|||||||
/**
|
/**
|
||||||
* returns a random password based on froxlor settings for min-length, included characters, etc.
|
* returns a random password based on froxlor settings for min-length, included characters, etc.
|
||||||
*
|
*
|
||||||
|
* @param int $length
|
||||||
|
* optional length of password, defaults to 10
|
||||||
|
*
|
||||||
* @access admin, customer
|
* @access admin, customer
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function generatePassword()
|
public function generatePassword()
|
||||||
{
|
{
|
||||||
return $this->response(Crypt::generatePassword());
|
$length = $this->getParam('length', true, 10);
|
||||||
|
return $this->response(Crypt::generatePassword($length));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -36,13 +36,15 @@ class Crypt
|
|||||||
/**
|
/**
|
||||||
* Generates a random password
|
* Generates a random password
|
||||||
*/
|
*/
|
||||||
public static function generatePassword()
|
public static function generatePassword(int $length = 0)
|
||||||
{
|
{
|
||||||
$alpha_lower = 'abcdefghijklmnopqrstuvwxyz';
|
$alpha_lower = 'abcdefghijklmnopqrstuvwxyz';
|
||||||
$alpha_upper = strtoupper($alpha_lower);
|
$alpha_upper = strtoupper($alpha_lower);
|
||||||
$numeric = '0123456789';
|
$numeric = '0123456789';
|
||||||
$special = Settings::Get('panel.password_special_char');
|
$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);
|
$pw = self::specialShuffle($alpha_lower);
|
||||||
$n = floor(($length) / 4);
|
$n = floor(($length) / 4);
|
||||||
|
|||||||
Reference in New Issue
Block a user