From eac7ef4d46170911406ffac55716d268116c33d3 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Fri, 5 Dec 2008 23:42:47 +0000 Subject: [PATCH] =?UTF-8?q?-=20LSsession=5FrecoverPassword=20/=20LSformEle?= =?UTF-8?q?ment=5Fpassword=20:=20=09->=20Modification=20de=20la=20fonction?= =?UTF-8?q?=20generatePassword()=20pour=20prendre=20en=20compte=20une=20?= =?UTF-8?q?=09politique=20de=20s=C3=A9curit=C3=A9=20plus=20complexe?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LSobjects/config.LSobjects.LSeepeople.php | 11 +++- trunk/includes/functions.php | 58 ++++++++++++++++--- 2 files changed, 58 insertions(+), 11 deletions(-) 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) {