Skip to content

Commit d94b1e2

Browse files
author
Till Brehm
committed
Merge branch 'stable-3.0.5' of git.ispconfig.org:ispconfig/ispconfig3 into stable-3.0.5
2 parents 743330f + 9c79079 commit d94b1e2

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

interface/lib/classes/auth.inc.php

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,44 @@ public function check_security_permissions($permission) {
153153

154154
}
155155

156-
public function get_random_password($length = 8) {
157-
$base64_alphabet='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
156+
public function get_random_password($minLength = 8, $special = false) {
157+
$minLength = $minLength || 10;
158+
if($minLength < 8) $minLength = 8;
159+
$maxLength = $minLength + 5;
160+
$length = mt_rand($minLength, $maxLength);
161+
162+
$alphachars = "abcdefghijklmnopqrstuvwxyz";
163+
$upperchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
164+
$numchars = "1234567890";
165+
$specialchars = "!@#_";
166+
167+
$num_special = 0;
168+
if($special == true) {
169+
$num_special = intval(mt_rand(0, round($length / 4))) + 1;
170+
}
171+
$numericlen = mt_rand(1, 2);
172+
$alphalen = $length - $num_special - $numericlen;
173+
$upperlen = intval($alphalen / 2);
174+
$alphalen = $alphalen - $upperlen;
158175
$password = '';
159-
for ($n=0;$n<$length;$n++) {
160-
$password.=$base64_alphabet[mt_rand(0, 63)];
176+
177+
for($i = 0; $i < $alphalen; $i++) {
178+
$password .= substr($alphachars, mt_rand(0, strlen($alphachars) - 1), 1);
179+
}
180+
181+
for($i = 0; $i < $upperlen; $i++) {
182+
$password .= substr($upperchars, mt_rand(0, strlen($upperchars) - 1), 1);
183+
}
184+
185+
for($i = 0; $i < $num_special; $i++) {
186+
$password .= substr($specialchars, mt_rand(0, strlen($specialchars) - 1), 1);
161187
}
162-
return $password;
188+
189+
for($i = 0; $i < $numericlen; $i++) {
190+
$password .= substr($numchars, mt_rand(0, strlen($numchars) - 1), 1);
191+
}
192+
193+
return str_shuffle($password);
163194
}
164195

165196
public function crypt_password($cleartext_password) {

interface/web/login/password_reset.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@
5757
$client = $app->db->queryOneRecord("SELECT * FROM client WHERE username = '$username' AND email = '$email'");
5858

5959
if($client['client_id'] > 0) {
60-
$new_password = $app->auth->get_random_password();
60+
$server_config_array = $app->getconf->get_global_config();
61+
$min_password_length = 8;
62+
if(isset($server_config_array['misc']['min_password_length'])) $min_password_length = $server_config_array['misc']['min_password_length'];
63+
64+
$new_password = $app->auth->get_random_password($min_password_length, true);
6165
$new_password_encrypted = $app->auth->crypt_password($new_password);
6266
$new_password_encrypted = $app->db->quote($new_password_encrypted);
6367

@@ -67,7 +71,7 @@
6771
$app->tpl->setVar("message", $wb['pw_reset']);
6872

6973
$app->uses('getconf,ispcmail');
70-
$mail_config = $app->getconf->get_global_config('mail');
74+
$mail_config = $server_config_array['mail'];
7175
if($mail_config['smtp_enabled'] == 'y') {
7276
$mail_config['use_smtp'] = true;
7377
$app->ispcmail->setOptions($mail_config);

0 commit comments

Comments
 (0)