diff --git a/trunk/conf/LSobjects/config.LSobjects.LSeepeople.php b/trunk/conf/LSobjects/config.LSobjects.LSeepeople.php index c7eebb66..71abc30e 100644 --- a/trunk/conf/LSobjects/config.LSobjects.LSeepeople.php +++ b/trunk/conf/LSobjects/config.LSobjects.LSeepeople.php @@ -435,8 +435,15 @@ $GLOBALS['LSobjects']['LSeepeople'] = array ( 'html_options' => array( 'generationTool' => true, 'autoGenerate' => false, - 'chars' => 'abcdefgh', - 'lenght' => 5, + 'lenght' => 8, + 'chars' => array ( + array( + 'nb' => 3, + 'chars' => 'abcdefijklmnopqrstuvwxyz' + ), + '0123456789', + '*$.:/_-[]{}=~' + ), 'mail' => array( 'send' => 1, 'ask' => 1, diff --git a/trunk/includes/functions.php b/trunk/includes/functions.php index 4995f161..bcc76230 100644 --- a/trunk/includes/functions.php +++ b/trunk/includes/functions.php @@ -332,19 +332,59 @@ function LSdebugDefined() { } function generatePassword($chars=NULL,$lenght=NULL) { + if (!$lenght) { + $lenght=8; + } + if (is_array($chars)) { + $retval=''; + foreach($chars as $chs) { + if (!is_array($chs)) { + $chs=array('chars' => $chs); + } + if (!is_int($chs['nb'])) { + $chs['nb']=1; + } + $retval.=aleaChar($chs['chars'],$chs['nb']); + } + $add = ($lenght-strlen($retval)); + if ($add > 0) { + $retval .= aleaChar($chars,$add); + } + return str_shuffle($retval); + } else { + return aleaChar($chars,$lenght); + } + } + + function aleaChar($chars=NULL,$lenght=1) { + if (is_array($chars)) { + $nchars=""; + foreach($chars as $chs) { + if (is_string($chs)) { + $nchars.=$chs; + } + else if (is_string($chs['chars'])) { + $nchars.=$chs['chars']; + } + } + if(strlen($chars)>0) { + $chars=$nchars; + } + else { + $chars=NULL; + } + } if (!$chars) { - $chars='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-'; + $chars='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-'; } $nbChars=strlen($chars); - - if (!$lenght) { - $lenght=8; + $retval=""; + if(is_int($lenght)) { + for ($i=0;$i<$lenght;$i++) { + $retval.=$chars[rand(0,$nbChars-1)]; + } } - $retVal=''; - for($i=0;$i<$lenght;$i++){ - $retVal.=$chars[rand(0,$nbChars-1)]; - } - return $retVal; + return $retval; } function compareDn($a,$b) {