Another Match: Because I can

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Another Match: Because I can

Post 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 ()  
&#123;  
    $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;  
&#125;  
?>
Guest

Post 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
&#123;
    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;
&#125;  
?>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

^ sorry forgot to log in :oops:
User avatar
hex
Forum Commoner
Posts: 92
Joined: Sat Apr 20, 2002 3:20 am
Location: UK

Post 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
&#123;
    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")) &#123;
        $rnd = rand(0, count($dictfile));
        return substr($dictfile&#1111;$rnd], mt_rand(0, 19), mt_rand(6, 12));
    &#125; else &#123;
        $password = mt_rand(1,99999999);
        $password = substr(md5($password), mt_rand(0, 19), mt_rand(6, 12));
        return $password;
    &#125;
&#125;
?>
DSM
Forum Contributor
Posts: 101
Joined: Thu May 02, 2002 11:51 am
Location: New Mexico, USA

Post 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 
&#123; 
    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")) &#123; 
        $rnd = rand(0, count($dictfile)); 
        return substr($dictfile&#1111;$rnd], mt_rand(0, 19), mt_rand(6, 12)); 
    &#125; else &#123; 
        $password = mt_rand(1,99999999); 
        $password = substr(md5($password), mt_rand(0, 19), mt_rand(6, 12)); 
        return $password; 
    &#125; 
&#125; 

//Form to generate password
function printForm()&#123;
print"<form action = '$PHP_SELF' method = 'post'>
<b>Generate Password</b>
<input type = 'submit' name = 'action' value = 'submit'></form>";
&#125;

?>
Guest

Post by Guest »

Code: Select all

<?php 
/* 
    string random_password ( void ) 
        Builds a random password 6 to 12 characters long 
*/ 
function random_password ($seed = FALSE)
&#123; 
    if (!$seed || (int)$seed == 0)
        $seed = (integer) md5(microtime()); 
    mt_srand($seed); 
    if ($dictfile = @file ("/usr/share/dict/words")) &#123; 
        $rnd = rand(0, count($dictfile));
        if(strlen($dictfile&#1111;$rnd]) < 32)  // reassure the string is long enough
           $dictfile&#1111;$rnd] .= md5(mt_rand(1,99999999));
        return substr($dictfile&#1111;$rnd], mt_rand(0, 19), mt_rand(6, 12)); 
    &#125; else &#123; 
        $password = mt_rand(1,99999999); 
        $password = substr(md5($password), mt_rand(0, 19), mt_rand(6, 12)); 
        return $password; 
    &#125; 
&#125; 


function printForm()&#123; 
print"<form action = '$PHP_SELF' method = 'post'> 
<b>Generate Password</b> 
<input type = 'submit' name = 'action' value = 'submit'></form>"; 
&#125; 

?>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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 :roll:
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post by protokol »

Code: Select all

<?php 
/* 
    string random_password ( void ) 
        Builds a random password 6 to 12 characters long 
*/ 
function random_password ($seed = FALSE)
&#123; 
    if (!$seed || (int)$seed == 0)
        $seed = (integer) md5(microtime()); 
    mt_srand($seed); 
    if ($dictfile = @file ("/usr/share/dict/words")) &#123; 
        $rnd = rand(0, count($dictfile));
        if(strlen($dictfile&#1111;$rnd]) < 32)  // reassure the string is long enough
           $dictfile&#1111;$rnd] .= md5(mt_rand(1,99999999));
        return substr($dictfile&#1111;$rnd], mt_rand(0, 19), mt_rand(6, 12)); 
    &#125; else &#123; 
        $password = mt_rand(1,99999999); 
        $password = substr(md5($password), mt_rand(0, 19), mt_rand(6, 12)); 
        return $password; 
    &#125; 
&#125; 

function printForm()&#123; 
print"<form action = '$PHP_SELF' method = 'post'> 
<b>Generate Password</b> 
<input type = 'submit' name = 'action' value = 'submit'></form>"; 
&#125; 

/*
<html><body>
<?php checkForm() ?>
</body></html>
*/
function checkForm() &#123;
   if ($_SERVER&#1111;'REQUEST_METHOD'] == 'GET'] &#123; printForm() &#125;
   elseif ($_SERVER&#1111;'REQUEST_METHOD'] == 'POST' && isset($_POST&#1111;'action'])) &#123; echo random_password() &#125;
&#125;
?>
User avatar
hex
Forum Commoner
Posts: 92
Joined: Sat Apr 20, 2002 3:20 am
Location: UK

Post by hex »

Line 36 is more than 80 chars! volka wins!
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post 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
User avatar
hex
Forum Commoner
Posts: 92
Joined: Sat Apr 20, 2002 3:20 am
Location: UK

Post 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!
User avatar
protokol
Forum Contributor
Posts: 353
Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:

Post 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
User avatar
llimllib
Moderator
Posts: 466
Joined: Mon Jul 01, 2002 2:19 pm
Location: Baltimore, MD

Post by llimllib »

Post what you think here
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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 :D )
Post Reply