Please see this code, I have generated it just for this question.
It's probably not the best way of doing it I'm sure, but this will work:
Edit: Turned into a function, so you can choose which length. Old code is below.
New code:
<?php
function GenerateRecoveryString($length)
{
$time=time();
$az="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
//$time and $az is just random stuff to generate a hash out of.
$output = md5($time.$az);//The soon to be 42 char string.
while(strlen($output)<$length)
{
$output.=md5($time.$az);//md5 only creates 32 bit strings - Lets create one that's 42 chars.
}
$output = substr($output, "0",$length);//The above example created 64 bit string - We need to cut it down.
str_shuffle($az);//Randomize the string above, to ensure a different output next time.
echo $output.' Length:'.strlen($output);
}
echo GenerateRecoveryString("42");
?>
<?php
$time=time();
$az="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
//$time and $az is just random stuff to generate a hash out of.
$output = md5($time.$az);//The soon to be 42 char string.
while(strlen($output)<"42")
{
$output.=md5($time.$az);//md5 only creates 32 bit strings - Lets create one that's 42 chars.
}
$output = substr($output, "0","42");//The above example created 64 bit string - We need to cut it down.
str_shuffle($az);//Randomize the string above, to ensure a different output next time.
echo $output.' Length:'.strlen($output);
?>