Skip to content

Commit 6d8d616

Browse files
committed
Create a util function to remove duplication
1 parent 04d8e6f commit 6d8d616

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

interface/lib/classes/auth.inc.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,36 @@ public function check_security_permissions($permission) {
188188

189189
}
190190

191+
/**
192+
* Get the minimum password length.
193+
*/
194+
public function get_min_password_length() {
195+
global $app;
196+
$server_config_array = $app->getconf->get_global_config();
197+
$min_password_length = 8;
198+
if(isset($server_config_array['misc']['min_password_length'])) $min_password_length = $server_config_array['misc']['min_password_length'];
199+
return $min_password_length;
200+
}
201+
202+
/**
203+
* Get the minimum password strength.
204+
*/
205+
public function get_min_password_strength() {
206+
global $app;
207+
$server_config_array = $app->getconf->get_global_config();
208+
$min_password_strength = 0;
209+
if(isset($server_config_array['misc']['min_password_strength'])) $min_password_strength = $server_config_array['misc']['min_password_strength'];;
210+
return $min_password_strength;
211+
}
212+
213+
/**
214+
* Generate a ranmdom password.
215+
*
216+
* @param int $minLength
217+
* Minimum number of characters.
218+
* @param boolean $special
219+
* Include special characters, like # and !
220+
*/
191221
public function get_random_password($minLength = 8, $special = false) {
192222
if($minLength < 8) $minLength = 8;
193223
$maxLength = $minLength + 5;

interface/lib/classes/validate_password.inc.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,8 @@ function password_check($field_name, $field_value, $validator) {
111111
$app->uses('ini_parser,getconf');
112112
$server_config_array = $app->getconf->get_global_config();
113113

114-
$min_password_strength = 0;
115-
$min_password_length = 5;
116-
if(isset($server_config_array['misc']['min_password_length'])) $min_password_length = $server_config_array['misc']['min_password_length'];
117-
if(isset($server_config_array['misc']['min_password_strength'])) $min_password_strength = $server_config_array['misc']['min_password_strength'];
114+
$min_password_length = $app->auth->get_min_password_length();
115+
$min_password_strength = $app->auth->get_min_password_strength();
118116

119117
if($min_password_strength > 0) {
120118
$lng_text = $app->lng('weak_password_txt');

interface/web/login/password_reset.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@
123123
} elseif ($continue) {
124124
if($client['client_id'] > 0) {
125125
$server_config_array = $app->getconf->get_global_config();
126-
$min_password_length = 8;
127-
if(isset($server_config_array['misc']['min_password_length'])) $min_password_length = $server_config_array['misc']['min_password_length'];
126+
$min_password_length = $app->auth->get_min_password_length();
128127

129128
$new_password = $app->auth->get_random_password($min_password_length, true);
130129
$new_password_encrypted = $app->auth->crypt_password($new_password);

0 commit comments

Comments
 (0)