Skip to content

Commit a3471bc

Browse files
committed
Create a util function to remove duplication
Lost on master(!866) ... now on cherry-picked on !1132
1 parent b0867b4 commit a3471bc

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
@@ -198,6 +198,36 @@ public function check_security_permissions($permission) {
198198

199199
}
200200

201+
/**
202+
* Get the minimum password length.
203+
*/
204+
public function get_min_password_length() {
205+
global $app;
206+
$server_config_array = $app->getconf->get_global_config();
207+
$min_password_length = 8;
208+
if(isset($server_config_array['misc']['min_password_length'])) $min_password_length = $server_config_array['misc']['min_password_length'];
209+
return $min_password_length;
210+
}
211+
212+
/**
213+
* Get the minimum password strength.
214+
*/
215+
public function get_min_password_strength() {
216+
global $app;
217+
$server_config_array = $app->getconf->get_global_config();
218+
$min_password_strength = 0;
219+
if(isset($server_config_array['misc']['min_password_strength'])) $min_password_strength = $server_config_array['misc']['min_password_strength'];;
220+
return $min_password_strength;
221+
}
222+
223+
/**
224+
* Generate a ranmdom password.
225+
*
226+
* @param int $minLength
227+
* Minimum number of characters.
228+
* @param boolean $special
229+
* Include special characters, like # and !
230+
*/
201231
public function get_random_password($minLength = 8, $special = false) {
202232
if($minLength < 8) $minLength = 8;
203233
$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
@@ -126,8 +126,7 @@
126126
} elseif ($continue) {
127127
if($client['client_id'] > 0) {
128128
$server_config_array = $app->getconf->get_global_config();
129-
$min_password_length = 8;
130-
if(isset($server_config_array['misc']['min_password_length'])) $min_password_length = $server_config_array['misc']['min_password_length'];
129+
$min_password_length = $app->auth->get_min_password_length();
131130

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

0 commit comments

Comments
 (0)