note 42482 added to control-structures.for

From: Date: Tue, 18 May 2004 16:28:33 +0000
Subject: note 42482 added to control-structures.for
Groups: php.notes 
Request: Send a blank email to php-notes+get-69778@lists.php.net to get a copy of this message
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; ?> ---- Manual Page -- http://www.php.net/manual/en/control-structures.for.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+42482 Delete -- http://master.php.net/manage/user-notes.php?action=delete+42482&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+42482&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#69778) next »