below function provide secure password and difficult to guess because it give you mix of A-Z , a-z , 0-9 , special character
function generate_random_password($length = 10)
{
$alphabets = range('A','Z');
$Smallalphabets = range('a','z');
$numbers = range('0','9');
$additional_characters = array('_','.');
$final_array = array_merge($alphabets,$Smallalphabets,$numbers,$additional_characters);
$password = '';
while($length--)
{
$key = array_rand($final_array);
$password .= $final_array[$key];
}
return $password;
}
call it to generate random password
$random_secure_password=generate_random_password(9);
you can make more complex by adding more special character like below code.
i add more special character at $additional_characters
function generate_random_password($length = 10)
{
$alphabets = range('A','Z');
$Smallalphabets = range('a','z');
$numbers = range('0','9');
$additional_characters = array('_','.',"#","$","%","@","!");
$final_array = array_merge($alphabets,$Smallalphabets,$numbers,$additional_characters);
$password = '';
while($length--)
{
$key = array_rand($final_array);
$password .= $final_array[$key];
}
return $password;
}
it make good random generated password which more secure and not easy to guess