Return to Snippet

Revision: 33444
at October 8, 2010 21:04 by stz184


Initial Code
function random_password($lenght=6, $text_transform='uppercase') {
    $index = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	//build array 
	for($i = 0; $i < mb_strlen($index); $i++) {
		$signs[] = mb_substr($index, $i, 1);
	}
	shuffle($signs);
	$password = '';
	for($i = 0; $i <= $lenght; $i++) {
		$password .= $signs[$i];
	}
	if($text_transform == 'lowercase') {
		return mb_strtolower($password);
	}
	elseif($text_transform == 'uppercase') {
		return mb_strtoupper($password);
	}
	else {
		return $password;
	}
}

Initial URL

                                

Initial Description
This function can be used to generate random passwords with specified length. Also, can use specified list of characters ($index)  and generate passwords with only lower or only upper case characters.

Initial Title
Random password generator

Initial Tags

                                

Initial Language
PHP