Here’s a random password and string generator function for PHP.
It is totally free of use.
randpass(); Will give you a 8 characters long randomized string with numbers and letters.
The function also takes these arguments:
$numchars <-- The length in characters for the returned string.
$digits <------ Should the generated password contain figures? 1/0
$letters <----- Should it contain letters? 1/0
$sensitive <--- Both upper and lower letters? 1/0
function randpass($numchars=8,$digits=1,$letters=1,$sensitive=0)
{
$dig = "12345678901234567890";
$abc = "abcdefghijklmnopqrstuvwxyz";
if($letters == 1)
{
$str .= $abc;
}
if($sensitive == 1)
{
$str .= strtoupper($abc);
}
if($digits == 1)
{
$str .= $dig;
}
for($i=0; $i < $numchars; $i++)
{
$randomized .= $str{rand() % strlen($str)};
}
return $randomized;
}
?>
To give an example of the code:
echo "Generated password: \n";
echo randpass(12,1,1,1);
?>
The code above will result in:
Generated password:
4C8cly61h907
Comments ( 0 )