note 26687 modified in function.chr by vrana

From: Date: Tue, 17 Aug 2004 14:54:50 +0000
Subject: note 26687 modified in function.chr by vrana
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-79931@lists.php.net to get a copy of this message
Here's a small function I wrote up to generate random passwords using the chr() function. <?php function randPass($len) { $pw = ''; //intialize to be blank for($i=0;$i<$len;$i++) { switch(rand(1,3)) { case 1: $pw.=chr(rand(48,57)); break; //0-9 case 2: $pw.=chr(rand(65,90)); break; //A-Z case 3: $pw.=chr(rand(97,122)); break; //a-z } } return $pw; } ?> Example: <?php $password = randPass(10); //assigns 10-character password ?> I found this useful in my early coding days... I'm sure someone else will too :D --was-- Here's a small function I wrote up to generate random passwords using the chr() function. function randPass($len) { $pw = ''; //intialize to be blank for($i=0;$i<$len;$i++) { switch(rand(1,3)) { case 1: $pw.=chr(rand(48,57)); break; //0-9 case 2: $pw.=chr(rand(65,90)); break; //A-Z case 3: $pw.=chr(rand(97,122)); break; //a-z } } return $pw; } Example: $password = randPass(10); //assigns 10-character password I found this useful in my early coding days... I'm sure someone else will too :D http://php.net/manual/en/function.chr.php

« previous php.notes (#79931) next »