Re: Re: rand_str

From: Date: Sun, 05 Aug 2001 15:46:02 +0000
Subject: Re: Re: rand_str
References: 1 2 3 4  Groups: php.dev 
Request: Send a blank email to php-dev+get-62155@lists.php.net to get a copy of this message
At 17:21 8/5/2001, Jeroen van Wolffelaar wrote the following: -------------------------------------------------------------- >>but why not put it into PEAR? >PEAR can be useful, but the power of PHP is, that is has so many helpful >build-in functions. And with pear, it will always be longer. > >> I think that new functions should be added on basis of >> usefulness, not the "coolness" factor. IMNSHO this function >> isn't very useful, > >To generate random passwords, with characters you decide, and length? I >think it is useful, but usefulness indeed is a good point. Does everyone >here doubt the usefulness? > >> and it is extremely easy to implement in >> userland: > >That is not true, So how about this? function str_rand($len=8) { $retval = strtr(md5(microtime()), chr(0x30), chr(0x4F)); return substr($retval,0,$len); } for($i=0; $i<10; $i++){ echo str_rand(), "\n"; } >md5 will always return hex, and is of specific length. I >can image users don't want (so much) digits, and/or want to exclude certain >look-alike chars ( 0 (zero) and O (o), for example). cynic@mail.cz ------------- And the eyes of them both were opened and they saw that their files were world readable and writable, so they chmoded 600 their files. - Book of Installation chapt 3 sec 7

« previous php.dev (#62155) next »