Skip to content

Commit ffb04de

Browse files
author
Marius Cramer
committed
- Changed password generation function
- Fixed password length in lost password function
1 parent 3299ad4 commit ffb04de

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
@@ -174,13 +174,44 @@ public function check_security_permissions($permission) {
174174

175175
}
176176

177-
public function get_random_password($length = 8) {
178-
$base64_alphabet='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
177+
public function get_random_password($minLength = 8, $special = false) {
178+
$minLength = $minLength || 10;
179+
if($minLength < 8) $minLength = 8;
180+
$maxLength = $minLength + 5;
181+
$length = mt_rand($minLength, $maxLength);
182+
183+
$alphachars = "abcdefghijklmnopqrstuvwxyz";
184+
$upperchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
185+
$numchars = "1234567890";
186+
$specialchars = "!@#_";
187+
188+
$num_special = 0;
189+
if($special == true) {
190+
$num_special = intval(mt_rand(0, round($length / 4))) + 1;
191+
}
192+
$numericlen = mt_rand(1, 2);
193+
$alphalen = $length - $num_special - $numericlen;
194+
$upperlen = intval($alphalen / 2);
195+
$alphalen = $alphalen - $upperlen;
179196
$password = '';
180-
for ($n=0;$n<$length;$n++) {
181-
$password.=$base64_alphabet[mt_rand(0, 63)];
197+
198+
for($i = 0; $i < $alphalen; $i++) {
199+
$password .= substr($alphachars, mt_rand(0, strlen($alphachars) - 1), 1);
200+
}
201+
202+
for($i = 0; $i < $upperlen; $i++) {
203+
$password .= substr($upperchars, mt_rand(0, strlen($upperchars) - 1), 1);
204+
}
205+
206+
for($i = 0; $i < $num_special; $i++) {
207+
$password .= substr($specialchars, mt_rand(0, strlen($specialchars) - 1), 1);
182208
}
183-
return $password;
209+
210+
for($i = 0; $i < $numericlen; $i++) {
211+
$password .= substr($numchars, mt_rand(0, strlen($numchars) - 1), 1);
212+
}
213+
214+
return str_shuffle($password);
184215
}
185216

186217
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
@@ -60,7 +60,11 @@
6060
$app->tpl->setVar("error", $wb['lost_password_function_disabled_txt']);
6161
} else {
6262
if($client['client_id'] > 0) {
63-
$new_password = $app->auth->get_random_password();
63+
$server_config_array = $app->getconf->get_global_config();
64+
$min_password_length = 8;
65+
if(isset($server_config_array['misc']['min_password_length'])) $min_password_length = $server_config_array['misc']['min_password_length'];
66+
67+
$new_password = $app->auth->get_random_password($min_password_length, true);
6468
$new_password_encrypted = $app->auth->crypt_password($new_password);
6569

6670
$username = $client['username'];
@@ -69,7 +73,7 @@
6973
$app->tpl->setVar("message", $wb['pw_reset']);
7074

7175
$app->uses('getconf,ispcmail');
72-
$mail_config = $app->getconf->get_global_config('mail');
76+
$mail_config = $server_config_array['mail'];
7377
if($mail_config['smtp_enabled'] == 'y') {
7478
$mail_config['use_smtp'] = true;
7579
$app->ispcmail->setOptions($mail_config);

0 commit comments

Comments
 (0)