diff --git a/doc/conf/LSattribute/LSattr_html/LSattr_html_password.docbook b/doc/conf/LSattribute/LSattr_html/LSattr_html_password.docbook index 8bbc93ae..2f4ca513 100644 --- a/doc/conf/LSattribute/LSattr_html/LSattr_html_password.docbook +++ b/doc/conf/LSattribute/LSattr_html/LSattr_html_password.docbook @@ -9,7 +9,7 @@ 'isLoginPassword' => [booleen], 'generationTool' => [booleen], 'autoGenerate' => [booleen], - 'lenght' => [nombre de caractères], + 'length' => [nombre de caractères], 'chars' => array ( // Caractères que peut contenir le mot de passe array( // Liste caractère avec un nombre mininum d'apparition supérieur à 1 'nb' => [nb caractères], @@ -72,7 +72,7 @@ - lenght + length Nombre de caractères que devront contenir les mots de passe générés. diff --git a/src/conf/LSobjects/config.LSobjects.LSpeople.php b/src/conf/LSobjects/config.LSobjects.LSpeople.php index ee734333..47c96867 100644 --- a/src/conf/LSobjects/config.LSobjects.LSpeople.php +++ b/src/conf/LSobjects/config.LSobjects.LSpeople.php @@ -542,7 +542,7 @@ $GLOBALS['LSobjects']['LSpeople'] = array ( 'viewHash' => true, 'autoGenerate' => false, 'confirmInput' => true, - 'lenght' => 8, + 'length' => 8, 'chars' => array ( array( 'nb' => 3, diff --git a/src/conf/LSobjects/config.LSobjects.LSsysaccount.php b/src/conf/LSobjects/config.LSobjects.LSsysaccount.php index 655a121b..091015ec 100644 --- a/src/conf/LSobjects/config.LSobjects.LSsysaccount.php +++ b/src/conf/LSobjects/config.LSobjects.LSsysaccount.php @@ -135,7 +135,7 @@ $GLOBALS['LSobjects']['LSsysaccount'] = array ( 'generationTool' => true, 'viewHash' => true, 'autoGenerate' => false, - 'lenght' => 12, + 'length' => 12, 'chars' => array ( array( 'nb' => 3, diff --git a/src/includes/class/class.LSformElement_password.php b/src/includes/class/class.LSformElement_password.php index da9eb98a..6f98d9ed 100644 --- a/src/includes/class/class.LSformElement_password.php +++ b/src/includes/class/class.LSformElement_password.php @@ -261,7 +261,13 @@ class LSformElement_password extends LSformElement { public static function generatePassword($params=NULL) { if (LSconfig :: get('html_options.use_pwgen', false, null, $params)) { $args = LSconfig :: get('html_options.pwgen_opts', '', 'string', $params); - $len = LSconfig :: get('html_options.lenght', 8, 'int', $params); + $len = LSconfig :: get( + 'html_options.length', + // Keep compatibility with historical typo (lenght vs length) + LSconfig :: get('html_options.lenght', 8, 'int', $params), + 'int', + $params + ); $bin = LSconfig :: get('html_options.pwgen_path', 'pwgen', 'string', $params); $cmd = "$bin ".escapeshellcmd($args)." $len 1"; exec($cmd,$ret,$retcode); @@ -275,7 +281,13 @@ class LSformElement_password extends LSformElement { } return generatePassword( LSconfig :: get('html_options.chars', null, null, $params), - LSconfig :: get('html_options.lenght', 8, 'int', $params) + LSconfig :: get( + 'html_options.length', + // Keep compatibility with historical typo (lenght vs length) + LSconfig :: get('html_options.lenght', 8, 'int', $params), + 'int', + $params + ) ); } diff --git a/src/includes/class/class.LSsession.php b/src/includes/class/class.LSsession.php index 81ee936c..e29abfea 100644 --- a/src/includes/class/class.LSsession.php +++ b/src/includes/class/class.LSsession.php @@ -1200,10 +1200,15 @@ class LSsession { $pwd_attr_name = LSauth :: getUserPasswordAttribute($user); if (array_key_exists($pwd_attr_name, $user -> attrs)) { $pwd_attr = $user -> attrs[$pwd_attr_name]; - $pwd = generatePassword( - $pwd_attr -> getConfig('html_options.chars'), - $pwd_attr -> getConfig('html_options.lenght') - ); + if (self :: loadLSclass('LSformElement_password')) { + $pwd = LSformElement_password :: generatePassword($pwd_attr->config); + } + else { + $pwd = generatePassword( + $pwd_attr -> getConfig('html_options.chars'), + $pwd_attr -> getConfig('html_options.length') + ); + } self :: log_debug("recoverPasswdSecondStep($user): new password = '$pwd'."); $lostPasswdForm = $user -> getForm('lostPassword'); $lostPasswdForm -> setPostData( diff --git a/src/includes/functions.php b/src/includes/functions.php index ddd08136..7c131e03 100644 --- a/src/includes/functions.php +++ b/src/includes/functions.php @@ -477,9 +477,9 @@ function checkEmail($value,$domain=NULL,$checkDns=true) { return true; } -function generatePassword($chars=NULL,$lenght=NULL) { - if (!$lenght) { - $lenght=8; +function generatePassword($chars=NULL,$length=NULL) { + if (!$length) { + $length=8; } if (is_array($chars)) { $retval=''; @@ -492,17 +492,17 @@ function generatePassword($chars=NULL,$lenght=NULL) { } $retval.=aleaChar($chs['chars'],$chs['nb']); } - $add = ($lenght-strlen($retval)); + $add = ($length-strlen($retval)); if ($add > 0) { $retval .= aleaChar($chars,$add); } return str_shuffle($retval); } else { - return aleaChar($chars,$lenght); + return aleaChar($chars,$length); } } -function aleaChar($chars=NULL,$lenght=1) { +function aleaChar($chars=NULL,$length=1) { if (is_array($chars)) { $nchars=""; foreach($chars as $chs) { @@ -525,8 +525,8 @@ function aleaChar($chars=NULL,$lenght=1) { } $nbChars=strlen($chars); $retval=""; - if(is_int($lenght)) { - for ($i=0;$i<$lenght;$i++) { + if(is_int($length)) { + for ($i=0;$i<$length;$i++) { $retval.=$chars[rand(0,$nbChars-1)]; } }