Over a million developers have joined DZone.

Random Password Generator In PHP

DZone's Guide to

Random Password Generator In PHP

Free Resource
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) {
for ($i=0;$i<=$length;$i++) {
	switch (mt_rand(1,3)) {
		case 1:
		case 2:
		case 3:
return $password;

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}