Re: Generating random keys

From: Date: Wed, 20 Dec 2000 21:22:18 +0000
Subject: Re: Generating random keys
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-31320@lists.php.net to get a copy of this message
I'm sure there's others out there, but here's a function that will do what you want: function randomkeygen($length) {
        mt_srand ((double) microtime() * 1000000);
        for($i = 0;$i < $length;$i++) {
                $random = mt_rand(0,61);
                if($random <= 9) {
                        $word .= "$random";
                };
                if(($random >= 10) and ($random <= 35)) {
                        $random += 55;
                        $word .= chr($random);
                };
                if(($random >= 36) and ($random <= 61)) {
                        $random += 61;
                        $word .= chr($random);
                };
        };
        return $word;
}; just call: $somevar = randomkeygen({int length}); and it will return a key of whatever length you specified. Matthew At 12:48 PM 12/20/2000 -0800, you wrote:
Is there a class/library for creating 6-8 character keys that have upper and lower case characters as well as digits? Todd -- Todd Cary Ariste Software todd@aristesoftware.com


« previous php.general (#31320) next »