note 9809 added to rand

From: Date: Sat, 25 Nov 2000 03:43:00 +0000
Subject: note 9809 added to rand
Groups: php.notes 
Request: Send a blank email to php-notes+get-8113@lists.php.net to get a copy of this message
Hi, I just wrote a quick and dirty random pass generator. It gets the $pass_len which will be the password length, it defaults to 10. It generates passwords which can contain a-z A-Z 0-9 but this can be easily changed by editing the mask of the eregi () function, but if you mess it up, You will end up in an infinite loop. :) There is no protection against but that rand generates really random numbers, which can be sentenced I think. In fact it uses mt_srand and mt_rand but those can be changed to rand and srand if desired. Hope some of you can use it or get idea. function generate_pass ($pass_len = 10) { $nps = ""; mt_srand ((double) microtime() * 1000000); while (strlen($nps)<$pass_len) { $c = chr(mt_rand (0,255)); if (eregi("^[a-z0-9]$", $c)) $nps = $nps.$c; }; return ($nps); }; Peace, Trapeer. http://www.php.net/manual/function.rand.php

« previous php.notes (#8113) next »