» tagged pages
» logout
PHP
Return to PHP Code Snippets

Random password generator in PHP

Tags Applied to this Entry

1 person has tagged this page:
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 $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;
}
Username:
Password:
(or Cancel)