$min=4;
$max=15;
$pwd=""; for($i=0;$i<rand($min,$max);$i++)
We need to get a load of letters now, but we have to be sure there are
valid letters and not other characters: $num=rand(48,122);
if(($num > 97 && $num < 122))
{
$pwd.=chr($num);
}
else if(($num > 65 && $num < 90))
{
$pwd.=chr($num);
}
else if(($num >48 && $num < 57))
{
$pwd.=chr($num);
}
else if($num==95)
{
$pwd.=chr($num);
}
Just a load of checking, nothing much really there. Because this is a
tutorial, we would output the result of our password: echo $pwd;
Be carefull about including that line for the final script. If you are
emailing the password then you don't need it, you decide. <?php
// filename "pword.php"
$min=4; // minimum length of password
$max=15; // maximum length of password
$pwd=""; // to store generated password
for($i=0;$i<rand($min,$max);$i++)
{
$num=rand(48,122);
if(($num > 97 && $num < 122))
{
$pwd.=chr($num);
}
else if(($num > 65 && $num < 90))
{
$pwd.=chr($num);
}
else if(($num >48 && $num < 57))
{
$pwd.=chr($num);
}
else if($num==95)
{
$pwd.=chr($num);
}
else
{
$i--;
}
}
echo $pwd; // prints the password
?>
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.