note 95414 modified in function.shuffle by thiago

From: Date: Mon, 04 Jan 2010 13:17:40 +0000
Subject: note 95414 modified in function.shuffle by thiago
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-164602@lists.php.net to get a copy of this message
Here is a quick function I wrote that generates a random password and uses shuffle() to easily shuffle the order. <?php public function randPass($upper = 3, $lower = 3, $numeric = 3, $other = 2) { //we need these vars to create a password string $passOrder = Array(); $passWord = ''; //generate the contents of the password for ($i = 0; $i < $upper; $i++) { $passOrder[] = chr(rand(65, 90)); } for ($i = 0; $i < $lower; $i++) { $passOrder[] = chr(rand(97, 122)); } for ($i = 0; $i < $numeric; $i++) { $passOrder[] = chr(rand(48, 57)); } for ($i = 0; $i < $other; $i++) { $passOrder[] = chr(rand(33, 47)); } //randomize the order of characters shuffle($passOrder); //concatenate into a string foreach ($passOrder as $char) { $passWord .= $char; } //we're done return $passWord; } ?> --was-- Here is a quick function I wrote that generates a random password and uses shuffle() to easily shuffle the order. public function randPass($upper = 3, $lower = 3, $numeric = 3, $other = 2) { //we need these vars to create a password string $passOrder = Array(); $passWord = ''; //generate the contents of the password for ($i = 0; $i < $upper; $i++) { $passOrder[] = chr(rand(65, 90)); } for ($i = 0; $i < $lower; $i++) { $passOrder[] = chr(rand(97, 122)); } for ($i = 0; $i < $numeric; $i++) { $passOrder[] = chr(rand(48, 57)); } for ($i = 0; $i < $other; $i++) { $passOrder[] = chr(rand(33, 47)); } //randomize the order of characters shuffle($passOrder); //concatenate into a string foreach ($passOrder as $char) { $passWord .= $char; } //we're done return $passWord; } http://php.net/manual/en/function.shuffle.php

« previous php.notes (#164602) next »