Page 1 of 2
Another Match: Because I can
Posted: Mon Jul 22, 2002 3:54 pm
by jason
Time Limit: None
Max Line Additions/Removals per Edit: 3
Restrictions: Backwards compatibility must be maintained. In other words, I should still be able to call random_password() and expect a 6 to 12 character password back, no matter what changes you make.
Code: Select all
<?php
/*
string random_password ( void )
Builds a random password 6 to 12 characters long
*/
function random_password ()
{
$seed = (integer) md5(microtime());
mt_srand($seed);
$password = mt_rand(1,99999999);
$password = substr(md5($password), mt_rand(0, 19), mt_rand(6, 12));
return $password;
}
?>
Posted: Mon Jul 22, 2002 5:38 pm
by Guest
Code: Select all
<?php
/*
string random_password ( void )
Builds a random password 6 to 12 characters long
*/
function random_password ($seed = FALSE) // add optional seed-parameter
{
if (!$seed || (int)$seed == 0) // generate seed if parameter not set or not a number (or zero)
$seed = (integer) md5(microtime());
mt_srand($seed);
$password = mt_rand(1,99999999);
$password = substr(md5($password), mt_rand(0, 19), mt_rand(6, 12));
return $password;
}
?>
Posted: Mon Jul 22, 2002 5:39 pm
by volka
^ sorry forgot to log in

Posted: Tue Jul 23, 2002 5:35 am
by hex
Code: Select all
<?php
/*
string random_password ( void )
Builds a random password 6 to 12 characters long
*/
function random_password ($seed = FALSE) // add optional seed-parameter
{
if (!$seed || (int)$seed == 0) // generate seed if parameter not set or not a number (or zero)
$seed = (integer) md5(microtime());
mt_srand($seed);
if ($dictfile = @file ("/usr/share/dict/words")) {
$rnd = rand(0, count($dictfile));
return substr($dictfileї$rnd], mt_rand(0, 19), mt_rand(6, 12));
} else {
$password = mt_rand(1,99999999);
$password = substr(md5($password), mt_rand(0, 19), mt_rand(6, 12));
return $password;
}
}
?>
Posted: Tue Jul 23, 2002 7:58 am
by DSM
Code: Select all
<?php
/*
string random_password ( void )
Builds a random password 6 to 12 characters long
*/
function random_password ($seed = FALSE) // add optional seed-parameter
{
if (!$seed || (int)$seed == 0) // generate seed if parameter not set or not a number (or zero)
$seed = (integer) md5(microtime());
mt_srand($seed);
if ($dictfile = @file ("/usr/share/dict/words")) {
$rnd = rand(0, count($dictfile));
return substr($dictfileї$rnd], mt_rand(0, 19), mt_rand(6, 12));
} else {
$password = mt_rand(1,99999999);
$password = substr(md5($password), mt_rand(0, 19), mt_rand(6, 12));
return $password;
}
}
//Form to generate password
function printForm(){
print"<form action = '$PHP_SELF' method = 'post'>
<b>Generate Password</b>
<input type = 'submit' name = 'action' value = 'submit'></form>";
}
?>
Posted: Tue Jul 23, 2002 9:45 am
by Guest
Code: Select all
<?php
/*
string random_password ( void )
Builds a random password 6 to 12 characters long
*/
function random_password ($seed = FALSE)
{
if (!$seed || (int)$seed == 0)
$seed = (integer) md5(microtime());
mt_srand($seed);
if ($dictfile = @file ("/usr/share/dict/words")) {
$rnd = rand(0, count($dictfile));
if(strlen($dictfileї$rnd]) < 32) // reassure the string is long enough
$dictfileї$rnd] .= md5(mt_rand(1,99999999));
return substr($dictfileї$rnd], mt_rand(0, 19), mt_rand(6, 12));
} else {
$password = mt_rand(1,99999999);
$password = substr(md5($password), mt_rand(0, 19), mt_rand(6, 12));
return $password;
}
}
function printForm(){
print"<form action = '$PHP_SELF' method = 'post'>
<b>Generate Password</b>
<input type = 'submit' name = 'action' value = 'submit'></form>";
}
?>
Posted: Tue Jul 23, 2002 9:49 am
by volka
sorry, forgot to login again

I just switched my IE6 to accept cookies only temporarily an forgot to add dnsprotect.com to the "always allow"-section - it's still devnetwork

Posted: Tue Jul 23, 2002 11:53 am
by protokol
Code: Select all
<?php
/*
string random_password ( void )
Builds a random password 6 to 12 characters long
*/
function random_password ($seed = FALSE)
{
if (!$seed || (int)$seed == 0)
$seed = (integer) md5(microtime());
mt_srand($seed);
if ($dictfile = @file ("/usr/share/dict/words")) {
$rnd = rand(0, count($dictfile));
if(strlen($dictfileї$rnd]) < 32) // reassure the string is long enough
$dictfileї$rnd] .= md5(mt_rand(1,99999999));
return substr($dictfileї$rnd], mt_rand(0, 19), mt_rand(6, 12));
} else {
$password = mt_rand(1,99999999);
$password = substr(md5($password), mt_rand(0, 19), mt_rand(6, 12));
return $password;
}
}
function printForm(){
print"<form action = '$PHP_SELF' method = 'post'>
<b>Generate Password</b>
<input type = 'submit' name = 'action' value = 'submit'></form>";
}
/*
<html><body>
<?php checkForm() ?>
</body></html>
*/
function checkForm() {
if ($_SERVERї'REQUEST_METHOD'] == 'GET'] { printForm() }
elseif ($_SERVERї'REQUEST_METHOD'] == 'POST' && isset($_POSTї'action'])) { echo random_password() }
}
?>
Posted: Tue Jul 23, 2002 12:01 pm
by hex
Line 36 is more than 80 chars! volka wins!
Posted: Tue Jul 23, 2002 12:03 pm
by protokol
Well, where in this thread and in Jason's rules does it give this rule to follow? I don't see it anywhere. So maybe you are mistaken
Posted: Tue Jul 23, 2002 12:20 pm
by hex
heh. this is why we need the rules laid out... the
original game that i played at sitepoint....
The VI Rule
Each line can be no more that 80 characters in width. Make sure you use a text editor that shows you character columns.
However, there are a few other rules we've overlooked as well... time to finalise the rules!
Posted: Tue Jul 23, 2002 12:23 pm
by protokol
That's fine then. Let's get some Official Rules going here .. maybe jason can make it a sticky announcement within the PHP Tennis forum
Posted: Tue Jul 23, 2002 12:28 pm
by llimllib
Posted: Tue Jul 23, 2002 1:46 pm
by jason
Actually, I believe Hex's first rewrite was the loosing script, as it did not maintain BC. I tried it, and got no password returned to me. Can anyone back this up? Hehe
Either way, we need our own rules.
Posted: Tue Jul 23, 2002 3:35 pm
by volka
I think it has 2 faults
- it doesn`t assure a 6-12 character long password (ok, depending on the dict-file)
- $rnd = rand(0, count($dictfile)); may choose "the line after the last line"
but who am I to judge ?
(hurray! been logged in on my first post

)