note 10415 added to rand

From: Date: Tue, 02 Jan 2001 18:21:16 +0000
Subject: note 10415 added to rand
Groups: php.notes 
Request: Send a blank email to php-notes+get-9250@lists.php.net to get a copy of this message
if make this with rand() function and i found it very good. this is a function called gen_pass you will get allway an another string. call it like: print "<form method=post action=$PHP_SELF> <input type=submit name=generate value=\"Generate IT\"><br><br>"; and here the code: if ($generate =="Generate IT"){ gen_pass(); } function gen_pass(){ //set rand() srand ( (double) microtime()*10000000); //set password lenght between 6 & 10 latters $rand_pass = rand(6,10); for ($i = 0;$i < $rand_pass; $i++){ $rand_num = rand(48,57); //random number $rand_lowcase = rand(97,122); //random low case $rand_upcase = rand(65,90); //random upper case $rand_choose = rand(1,3); //random choose between low, uppercase and numbers (see switch)! //declare function to output with help of chr() $num = $rand_num ; $lowcase = chr($rand_lowcase); $upcase = chr($rand_upcase); switch ($rand_choose){ //if $rand_choose 1 then use $rand_num, 2 --> $rand_lowcase, 3 --> $rand_upcase case 1: $pass = $pass. $num; break; case 2: $pass = $pass. $lowcase; break; case 3: $pass = $pass. $upcase; break; } } print "Your password: $pass"; } cappa http://www.php.net/manual/function.rand.php

« previous php.notes (#9250) next »