- LSsession_recoverPassword / LSformElement_password :

-> Modification de la fonction generatePassword() pour prendre en compte une
	politique de sécurité plus complexe
This commit is contained in:
Benjamin Renard 2008-12-05 23:42:47 +00:00
parent 6529d0b3bf
commit eac7ef4d46
2 changed files with 58 additions and 11 deletions

View file

@ -435,8 +435,15 @@ $GLOBALS['LSobjects']['LSeepeople'] = array (
'html_options' => array( 'html_options' => array(
'generationTool' => true, 'generationTool' => true,
'autoGenerate' => false, 'autoGenerate' => false,
'chars' => 'abcdefgh', 'lenght' => 8,
'lenght' => 5, 'chars' => array (
array(
'nb' => 3,
'chars' => 'abcdefijklmnopqrstuvwxyz'
),
'0123456789',
'*$.:/_-[]{}=~'
),
'mail' => array( 'mail' => array(
'send' => 1, 'send' => 1,
'ask' => 1, 'ask' => 1,

View file

@ -332,19 +332,59 @@ function LSdebugDefined() {
} }
function generatePassword($chars=NULL,$lenght=NULL) { 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) { if (!$chars) {
$chars='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-'; $chars='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-';
} }
$nbChars=strlen($chars); $nbChars=strlen($chars);
$retval="";
if (!$lenght) { if(is_int($lenght)) {
$lenght=8; 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) { function compareDn($a,$b) {