Return to Snippet

Revision: 14325
at May 29, 2009 16:13 by fackz


Initial Code
<?php
function create_password($length=8,$use_upper=1,$use_lower=1,$use_number=1,$use_custom=""){
	$upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	$lower = "abcdefghijklmnopqrstuvwxyz";
	$number = "0123456789";
	if($use_upper){
		$seed_length += 26;
		$seed .= $upper;
	}
	if($use_lower){
		$seed_length += 26;
		$seed .= $lower;
	}
	if($use_number){
		$seed_length += 10;
		$seed .= $number;
	}
	if($use_custom){
		$seed_length +=strlen($use_custom);
		$seed .= $use_custom;
	}
	for($x=1;$x<=$length;$x++){
		$password .= $seed{rand(0,$seed_length-1)};
	}
	return($password);
}
?>

USAGE:

<?php
echo create_password(); // Returns for example a7YmTwG4
echo create_password(16); // Returns for example Z77OzzS3DgV3OxxP
echo create_password(8,0,0); // Returns for example 40714215
echo create_password(10,1,1,1,";,:.-_()"); // Returns for example or)ZA10kpX
?>

Initial URL

                                

Initial Description
Let' see the parameters

lenght: is the password length (default = 8)

use_upper: set to 0 if you do not want to use uppercase chars (ABCD...), any other value otherwise. Default = 1

use_lower: set to 0 if you do not want to use lowercase chars (abcd...), any other value otherwise. Default = 1
use_number: set to 0 if you do not want to use number chars (0123...), any other value otherwise. Default = 1

use_custom: a string representing any extra char you want (such as ?*_ ...). Default = empy string

Initial Title
Php password generator

Initial Tags

                                

Initial Language
PHP