Hi,

It is not a good idea to seed the random number generator inside the for
loop. It should only be seeded once during the execution of a script.
Your function could be susceptible to time attacks as it may not be
difficult to guess the seeding pattern and hence guess what random
numbers were actually produced (in this case always the first random
number in a given sequence).

Also, note from the documentation

<snip>
Note:  Since PHP 4.2.0 it's no longer necessary to seed the random
number generator before using it. 
</snip>

Regards,

Abdul-Wahid



On Wed, 2003-03-19 at 08:30, Michael Egan wrote:
> I put together the following function to give me a password consisting of random 
> letters and numbers.  It should be fairly clear as to how you'd need to tweak it to 
> just give you the characters you'd need interspersed with spaces.
> 
> Hope this helps - I also hope anybody else is fairly gentle with their criticisms 
> and pointers to whatever is wrong with the script - this is the first time I've 
> ventured to include something like this in a response to an email on the list :-(
> 
> 
>    function get_password()
>    {
>       // Create the password variable as an array
>       $temp_password = array();
>       // Create an array of the letters of the alphabet
>       $letters = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
>                        "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
>                        "w", "x", "y", "z");
>       // Get the first three alpha characters of the password
>       for($row = 0; $row < 3; $row ++)
>       {
>         srand ((double) microtime() * 1000000);
>         $rand_number = rand(0, 25);
>         $letter = $letters[$rand_number];
>         array_push($temp_password, $letter);
>       }
>       // Get five numeric characters to complete the password
>       for($row = 0; $row < 5; $row ++)
>       {
>         srand ((double) microtime() * 1000000);
>         $rand_number = rand(0, 9);
>         array_push($temp_password, $rand_number);
>       }
>       // Convert the array into a single string
>       for ($row = 0; $row < count($temp_password); $row ++)
>       {
>         $password .=  $temp_password[$row];
>       }
>       // Return the password to the script that called the function
>       return $password;
>    }
> 
> 
> By the way - I put this together one evening after consuming five pints of Jameson's 
> with one arm tied behind my back and whilst wearing a blindfold!
> 
> 
> Michael Egan
> 
> 
> 
> -----Original Message-----
> From: Bryan Koschmann - GKT [mailto:[EMAIL PROTECTED]
> Sent: 19 March 2003 07:44
> To: PHP General
> Subject: [PHP] random letter/character?[Scanned]
> 
> 
> Hi,
> 
> I need to get a php script to print out a list of random characters. This
> is the list:
> 
> a'
> b'
> c'
> d'
> e'
> f'
> g'
> a''
> b''
> c''
> d''
> e''
> f''
> g''
> 
> They would be printed to a maximum of 50 in a row separated by spaces. Can
> anyone give me a pointer as to how to do this? Since the rand functions
> are only for numbers, maybe assign each character group a number?
> 
> Thanks in advance!
> 
>       Bryan
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
-- 
Abdul-Wahid Paterson

Lintrix Networking & Communications ltd.
Web: http://www.lintrix.net/
Tel: +44 7801 070621
Email/Jabber: [EMAIL PROTECTED]
--------------------------------------------------------------------
Web-Hosting  |  Development  |  Security  |  Consultancy  |  Domains
--------------------------------------------------------------------

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to