note 42482 deleted from control-structures.for by tomsommer
| From: | tomsommer@php.net | Date: | Thu, 05 Aug 2004 18:28:16 +0000 |
| Subject: | note 42482 deleted from control-structures.for by tomsommer | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-74069@lists.php.net to get a copy of this message | ||
Note Submitter: </Life>
----
You can also easily generate random passwords using "for":
<?PHP
// ->
define('CHARPOOL', 'ABC..YZab..yz0..9'); // The characters that may
appear in the password.
define('CHARPOOL_MAXINDEX', strlen(CHARPOOL)-1); // maximum character index of a string
is length-1
define('PASSWORD_LENGTH', 8); // The length of the generated password. To generate
passwords with variable length use mt_rand(min_length,max_length) for this.
// <- You might want to use these values directly within the for-loop,
// but for the reason of readability they are defined as constants here.
for ($passwd=''; strlen($passwd)<PASSWORD_LENGTH;
$passwd.=substr(CHARPOOL,CHARPOOL_MAXINDEX));
echo 'Generated password is: '.$passwd;
?>