Page 1 of 1
Randomisation
Posted: Sat Jan 20, 2007 3:42 am
by DeathsMessenger
Code: Select all
<?php
function createRandomPassword()
{
$chars = "abcdefghijkmnopqrstuvwxyz023456789";
srand((double)microtime()*1000000);
$i = 0;
$pass = '' ;
while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($chars, $num, 1);
$pass = $pass . $tmp;
$i++;
}
return $pass;
}
$password = createRandomPassword();
echo "Your random password is: $password";
?>
theoreticly this should work right?
i can't test it cause my mate changed my server password
Also im tryng to figure out how to randomise it so it loads a certain picture or page
Posted: Sat Jan 20, 2007 7:57 am
by Kieran Huggins
it would be a whole lot easier to use a
substr() of an
md5() of some random thing
Posted: Sat Jan 20, 2007 2:10 pm
by Ollie Saunders
it would be a whole lot easier to use a substr() of an md5() of some random thing
You don't get a full complement of characters then.
i can't test it cause my mate changed my server password
Hmm you should remedy that. Perhaps install Apache/PHP on your computer. Here's a better version of your function:
Code: Select all
<?php
function getRandomPassword($len = 7)
{
$pass = '';
$chars = '0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]_abcdefghijklmnopqrstuvwxyz';
$lastCharIndex = strlen($chars) - 1;
while ($len--) {
$pass.= $chars[mt_rand(0, $lastCharIndex)];
}
return $pass;
}
tested.
Posted: Sun Jan 21, 2007 2:24 am
by DeathsMessenger
thanks i was trying to get it right for ages.
And ole? Installing it now.