qwertyjjj
11-09-2012, 06:01 PM
This code has worked for ages so am not sure what is wrong now.
Line 31 is the srand line:
//function
function generatePassword($length=6,$level=2){
list($usec, $sec) = explode(' ', microtime());
srand((float) $sec ((float) $usec * 100000));
$validchars[1] = "23456789abcdefghjkmnpqrstuvwxyz";
$validchars[2] = "23456789abcdefghjkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ";
$validchars[3] = "23456789_!@#$%&*()-= /abcdefghjkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ_!@#$%&*()-= /";
$password = "";
$counter = 0;
while ($counter < $length) {
$actChar = substr($validchars[$level], rand(0, strlen($validchars[$level])-1), 1);
// All character must be different
if (!strstr($password, $actChar)) {
$password .= $actChar;
$counter ;
}
}
return $password;
}
Line 31 is the srand line:
//function
function generatePassword($length=6,$level=2){
list($usec, $sec) = explode(' ', microtime());
srand((float) $sec ((float) $usec * 100000));
$validchars[1] = "23456789abcdefghjkmnpqrstuvwxyz";
$validchars[2] = "23456789abcdefghjkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ";
$validchars[3] = "23456789_!@#$%&*()-= /abcdefghjkmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ_!@#$%&*()-= /";
$password = "";
$counter = 0;
while ($counter < $length) {
$actChar = substr($validchars[$level], rand(0, strlen($validchars[$level])-1), 1);
// All character must be different
if (!strstr($password, $actChar)) {
$password .= $actChar;
$counter ;
}
}
return $password;
}