Hey, I am attempting to create a random password string, and I am getting a timeout error on the regular expression. its giving me errors on the checks. line 25/27/29/31
[code=php]
function gen_secure($ran d_len = false)
{
$config = array(
0 => "EXDHKFRLACYZJS WMPVGBNUT",
1 => "jhwzqbgkmadovr snxyftpicue",
2 => "47358926",
3 => "`~!@#$^&*( )_-+=\\}]{[:;?/><",
);
if($rand_len)
$length = rand(MIN_LEN,MA X_LEN);
else
$length = 8;
$pass = '';
for($i=0; $i<$length; $i++)
{
$tring = str_shuffle($co nfig[rand(0,count($c onfig))]);
$int_start = rand(0, strlen($tring))-1;
//Adds the character to the end of the password
$pass .= substr($tring, $int_start, 1);
}
do
{
if( preg_match("/[A-Z]+/",$pass) )
// Picks a random character in the string, grabs random character from array, replaces that 1 character
$pass = str_replace( substr($pass, rand(0,$length) ,1), substr($config[0],rand(0, strlen($config[0])-1), 1), $pass );
if( preg_match("/[a-z]+/",$pass) )
$pass = str_replace( substr($pass, rand(0,$length) ,1), substr($config[1],rand(0, strlen($config[1])-1), 1), $pass );
if( preg_match("/[0-9]+/",$pass) )
$pass = str_replace( substr($pass, rand(0,$length) ,1), substr($config[2],rand(0, strlen($config[2])-1), 1), $pass );
if( preg_match("/[\W]+/",$pass) )
$pass = str_replace( substr($pass, rand(0,$length) ,1), substr($config[3],rand(0, strlen($config[3])-1), 1), $pass );
}
while( !preg_match("/([A-Z]+[a-z]+[0-9]+){".$length." }/",$pass) );
return $pass;
}
[/code]
[code=php]
function gen_secure($ran d_len = false)
{
$config = array(
0 => "EXDHKFRLACYZJS WMPVGBNUT",
1 => "jhwzqbgkmadovr snxyftpicue",
2 => "47358926",
3 => "`~!@#$^&*( )_-+=\\}]{[:;?/><",
);
if($rand_len)
$length = rand(MIN_LEN,MA X_LEN);
else
$length = 8;
$pass = '';
for($i=0; $i<$length; $i++)
{
$tring = str_shuffle($co nfig[rand(0,count($c onfig))]);
$int_start = rand(0, strlen($tring))-1;
//Adds the character to the end of the password
$pass .= substr($tring, $int_start, 1);
}
do
{
if( preg_match("/[A-Z]+/",$pass) )
// Picks a random character in the string, grabs random character from array, replaces that 1 character
$pass = str_replace( substr($pass, rand(0,$length) ,1), substr($config[0],rand(0, strlen($config[0])-1), 1), $pass );
if( preg_match("/[a-z]+/",$pass) )
$pass = str_replace( substr($pass, rand(0,$length) ,1), substr($config[1],rand(0, strlen($config[1])-1), 1), $pass );
if( preg_match("/[0-9]+/",$pass) )
$pass = str_replace( substr($pass, rand(0,$length) ,1), substr($config[2],rand(0, strlen($config[2])-1), 1), $pass );
if( preg_match("/[\W]+/",$pass) )
$pass = str_replace( substr($pass, rand(0,$length) ,1), substr($config[3],rand(0, strlen($config[3])-1), 1), $pass );
}
while( !preg_match("/([A-Z]+[a-z]+[0-9]+){".$length." }/",$pass) );
return $pass;
}
[/code]
Comment