note 28446 added to function.rand
| From: | ogresamanosuke at hotmail dot com | Date: | Mon, 13 Jan 2003 19:48:07 +0000 |
| Subject: | note 28446 added to function.rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-42069@lists.php.net to get a copy of this message | ||
In addition to the above password code, you could also use 'gettimeofday' to get a random
string, MD5 it, and substr it down to your desired value. The problem of this, of course, is it can
be deciphered if the time of day the pass was made is figured out. (IE: if a hacker knew it was
between 5:10am and 5:15am on X day, he could shorten his checking area)
The nice advantage of the method you posted is that you not only control what content, but it
actually takes less time to do it in that fashion. The one thing I can suggest to anyone taking the
example though, is to replace this line:
$password .= substr($passwordChars,$randomNumber-1,1)
with this line:
$password.=$passwordChars{$randomNumber};
to speed things up a little. (Microseconds, but still.)
--
http://www.php.net/manual/en/function.rand.php
http://master.php.net/manage/user-notes.php?action=edit+28446
http://master.php.net/manage/user-notes.php?action=delete+28446
http://master.php.net/manage/user-notes.php?action=reject+28446