DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Random Password Generator In PHP
A little function which generates random password of a certain length. It uses all letters, both lowercase and uppercase and all numbers.
//generates a random password which contains all letters (both uppercase and lowercase) and all numbers
function generatePassword($length) {
$password='';
for ($i=0;$i<=$length;$i++) {
$chr='';
switch (mt_rand(1,3)) {
case 1:
$chr=chr(mt_rand(48,57));
break;
case 2:
$chr=chr(mt_rand(65,90));
break;
case 3:
$chr=chr(mt_rand(97,122));
}
$password.=$chr;
}
return $password;
}




