note 33156 added to function.rand

From: Date: Tue, 17 Jun 2003 22:53:46 +0000
Subject: note 33156 added to function.rand
Groups: php.notes 
Request: Send a blank email to php-notes+get-50536@lists.php.net to get a copy of this message
Viewing the comments and the random password scripts listed i figured i'd show my simple but effective password generator. function ranpass($len = "8"){ $pass = NULL; for($i=0; $i<$len; $i++) { $char = chr(rand(48,122)); while (!ereg("[a-zA-Z0-9]", $char)){ if($char == $lchar) continue; $char = chr(rand(48,90)); } $pass .= $char; $lchar = $char; } return $pass; } usage: $password = ranpass(); // Will generate a 8 charater password $password = ranpass(6); // Will generate a 6 character password The password will not repeat two characters in a row. For example you wont recieve like kEg64AA but you might recieve kEg64Aa. I tested up to 9999 characters and it went fast even with a number that big. ---- Manual Page -- http://www.php.net/manual/en/function.rand.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33156 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33156&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33156&report=yes

« previous php.notes (#50536) next »