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:
Post
by jason » Mon Jul 22, 2002 3:54 pm
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;
}
?>
Guest
Post
by Guest » Mon Jul 22, 2002 5:38 pm
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;
}
?>
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Mon Jul 22, 2002 5:39 pm
^ sorry forgot to log in
hex
Forum Commoner
Posts: 92 Joined: Sat Apr 20, 2002 3:20 am
Location: UK
Post
by hex » Tue Jul 23, 2002 5:35 am
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;
}
}
?>
DSM
Forum Contributor
Posts: 101 Joined: Thu May 02, 2002 11:51 am
Location: New Mexico, USA
Post
by DSM » Tue Jul 23, 2002 7:58 am
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>";
}
?>
Guest
Post
by Guest » Tue Jul 23, 2002 9:45 am
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>";
}
?>
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Tue Jul 23, 2002 9:49 am
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
protokol
Forum Contributor
Posts: 353 Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:
Post
by protokol » Tue Jul 23, 2002 11:53 am
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() }
}
?>
hex
Forum Commoner
Posts: 92 Joined: Sat Apr 20, 2002 3:20 am
Location: UK
Post
by hex » Tue Jul 23, 2002 12:01 pm
Line 36 is more than 80 chars! volka wins!
protokol
Forum Contributor
Posts: 353 Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:
Post
by protokol » Tue Jul 23, 2002 12:03 pm
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
hex
Forum Commoner
Posts: 92 Joined: Sat Apr 20, 2002 3:20 am
Location: UK
Post
by hex » Tue Jul 23, 2002 12:20 pm
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!
protokol
Forum Contributor
Posts: 353 Joined: Fri Jun 21, 2002 7:00 pm
Location: Cleveland, OH
Contact:
Post
by protokol » Tue Jul 23, 2002 12:23 pm
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
llimllib
Moderator
Posts: 466 Joined: Mon Jul 01, 2002 2:19 pm
Location: Baltimore, MD
Post
by llimllib » Tue Jul 23, 2002 12:28 pm
jason
Site Admin
Posts: 1767 Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:
Post
by jason » Tue Jul 23, 2002 1:46 pm
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.
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Tue Jul 23, 2002 3:35 pm
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
)