remove password-suggestion if a custom regex is defined; added password-complexity-settings for non-regex users to define what generated passwords should contain, thx to Marco Vogt; fixes #1216
Signed-off-by: Michael Kaufmann (d00p) <d00p@froxlor.org>
This commit is contained in:
@@ -38,6 +38,7 @@ return array(
|
||||
'admin_password_suggestion' => array(
|
||||
'label' => $lng['customer']['generated_pwd'],
|
||||
'type' => 'text',
|
||||
'visible' => (Settings::Get('panel.password_regex') == ''),
|
||||
'value' => generatePassword(),
|
||||
),
|
||||
'def_language' => array(
|
||||
|
||||
@@ -47,6 +47,7 @@ return array(
|
||||
'admin_password_suggestion' => array(
|
||||
'label' => $lng['customer']['generated_pwd'],
|
||||
'type' => 'text',
|
||||
'visible' => (Settings::Get('panel.password_regex') == ''),
|
||||
'value' => generatePassword(),
|
||||
'visible' => ($result['adminid'] == $userinfo['userid'] ? false : true)
|
||||
),
|
||||
|
||||
@@ -52,6 +52,7 @@ return array(
|
||||
'new_customer_password_suggestion' => array(
|
||||
'label' => $lng['customer']['generated_pwd'],
|
||||
'type' => 'text',
|
||||
'visible' => (Settings::Get('panel.password_regex') == ''),
|
||||
'value' => generatePassword(),
|
||||
),
|
||||
'sendpassword' => array(
|
||||
|
||||
@@ -58,6 +58,7 @@ return array(
|
||||
'new_customer_password_suggestion' => array(
|
||||
'label' => $lng['customer']['generated_pwd'],
|
||||
'type' => 'text',
|
||||
'visible' => (Settings::Get('panel.password_regex') == ''),
|
||||
'value' => generatePassword(),
|
||||
),
|
||||
'def_language' => array(
|
||||
|
||||
@@ -37,6 +37,7 @@ return array(
|
||||
'email_password_suggestion' => array(
|
||||
'label' => $lng['customer']['generated_pwd'],
|
||||
'type' => 'text',
|
||||
'visible' => (Settings::Get('panel.password_regex') == ''),
|
||||
'value' => generatePassword(),
|
||||
)
|
||||
)
|
||||
|
||||
@@ -37,6 +37,7 @@ return array(
|
||||
'email_password_suggestion' => array(
|
||||
'label' => $lng['customer']['generated_pwd'],
|
||||
'type' => 'text',
|
||||
'visible' => (Settings::Get('panel.password_regex') == ''),
|
||||
'value' => generatePassword(),
|
||||
),
|
||||
'email_quota' => array(
|
||||
|
||||
@@ -43,6 +43,7 @@ return array(
|
||||
'directory_password_suggestion' => array(
|
||||
'label' => $lng['customer']['generated_pwd'],
|
||||
'type' => 'text',
|
||||
'visible' => (Settings::Get('panel.password_regex') == ''),
|
||||
'value' => generatePassword(),
|
||||
),
|
||||
'directory_authname' => array(
|
||||
|
||||
@@ -42,6 +42,7 @@ return array(
|
||||
'directory_password_suggestion' => array(
|
||||
'label' => $lng['customer']['generated_pwd'],
|
||||
'type' => 'text',
|
||||
'visible' => (Settings::Get('panel.password_regex') == ''),
|
||||
'value' => generatePassword(),
|
||||
),
|
||||
'directory_authname' => array(
|
||||
|
||||
@@ -53,6 +53,7 @@ return array(
|
||||
'ftp_password_suggestion' => array(
|
||||
'label' => $lng['customer']['generated_pwd'],
|
||||
'type' => 'text',
|
||||
'visible' => (Settings::Get('panel.password_regex') == ''),
|
||||
'value' => generatePassword(),
|
||||
),
|
||||
'sendinfomail' => array(
|
||||
|
||||
@@ -49,6 +49,7 @@ return array(
|
||||
'ftp_password_suggestion' => array(
|
||||
'label' => $lng['customer']['generated_pwd'],
|
||||
'type' => 'text',
|
||||
'visible' => (Settings::Get('panel.password_regex') == ''),
|
||||
'value' => generatePassword(),
|
||||
)
|
||||
)
|
||||
|
||||
@@ -41,6 +41,7 @@ return array(
|
||||
'mysql_password_suggestion' => array(
|
||||
'label' => $lng['customer']['generated_pwd'],
|
||||
'type' => 'text',
|
||||
'visible' => (Settings::Get('panel.password_regex') == ''),
|
||||
'value' => generatePassword(),
|
||||
),
|
||||
'sendinfomail' => array(
|
||||
|
||||
@@ -47,6 +47,7 @@ return array(
|
||||
'mysql_password_suggestion' => array(
|
||||
'label' => $lng['customer']['generated_pwd'],
|
||||
'type' => 'text',
|
||||
'visible' => (Settings::Get('panel.password_regex') == ''),
|
||||
'value' => generatePassword(),
|
||||
)
|
||||
)
|
||||
|
||||
@@ -19,8 +19,28 @@
|
||||
* Generates a random password
|
||||
*/
|
||||
function generatePassword() {
|
||||
return substr(
|
||||
base64_encode(sha1(md5(uniqid(microtime(), 1))).md5(uniqid(microtime(), 1)).sha1(md5(uniqid(microtime(), 1)))),
|
||||
rand(5, 50), (Settings::Get('panel.password_min_length') > 0 ? Settings::Get('panel.password_min_length') : 10)
|
||||
);
|
||||
$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;
|
||||
|
||||
$pw = str_shuffle($alpha_lower);
|
||||
$n = floor(($length)/4);
|
||||
|
||||
if (Settings::Get('panel.password_alpha_upper')) {
|
||||
$pw .= substr(str_shuffle($alpha_upper), 0, $n);
|
||||
}
|
||||
|
||||
if (Settings::Get('panel.password_numeric')) {
|
||||
$pw .= substr(str_shuffle($numeric), 0, $n);
|
||||
}
|
||||
|
||||
if (Settings::Get('panel.password_special_char_required')) {
|
||||
$pw .= substr(str_shuffle($special), 0, $n);
|
||||
}
|
||||
|
||||
$pw = substr($pw, -$length);
|
||||
|
||||
return str_shuffle($pw);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ function validatePassword($password = null) {
|
||||
|
||||
if (Settings::Get('panel.password_min_length') > 0) {
|
||||
$password = validate(
|
||||
$password,
|
||||
$password,
|
||||
Settings::Get('panel.password_min_length'),
|
||||
'/^.{'.(int)Settings::Get('panel.password_min_length').',}$/D',
|
||||
'notrequiredpasswordlength'
|
||||
@@ -39,11 +39,44 @@ function validatePassword($password = null) {
|
||||
|
||||
if (Settings::Get('panel.password_regex') != '') {
|
||||
$password = validate(
|
||||
$password,
|
||||
$password,
|
||||
Settings::Get('panel.password_regex'),
|
||||
Settings::Get('panel.password_regex'),
|
||||
'notrequiredpasswordcomplexity'
|
||||
);
|
||||
} else {
|
||||
if (Settings::Get('panel.password_alpha_lower')) {
|
||||
$password = validate(
|
||||
$password,
|
||||
'/.*[a-z]+.*/',
|
||||
'/.*[a-z]+.*/',
|
||||
'notrequiredpasswordcomplexity'
|
||||
);
|
||||
}
|
||||
if (Settings::Get('panel.password_alpha_upper')) {
|
||||
$password = validate(
|
||||
$password,
|
||||
'/.*[A-Z]+.*/',
|
||||
'/.*[A-Z]+.*/',
|
||||
'notrequiredpasswordcomplexity'
|
||||
);
|
||||
}
|
||||
if (Settings::Get('panel.password_numeric')) {
|
||||
$password = validate(
|
||||
$password,
|
||||
'/.*[0-9]+.*/',
|
||||
'/.*[0-9]+.*/',
|
||||
'notrequiredpasswordcomplexity'
|
||||
);
|
||||
}
|
||||
if (Settings::Get('panel.password_special_char_required')) {
|
||||
$password = validate(
|
||||
$password,
|
||||
'/.*[' . preg_quote(Settings::Get('panel.password_special_char')) . ']+.*/',
|
||||
'/.*[' . preg_quote(Settings::Get('panel.password_special_char')) . ']+.*/',
|
||||
'notrequiredpasswordcomplexity'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $password;
|
||||
|
||||
Reference in New Issue
Block a user