Location: PHPKode > scripts > PasswordGen > passwordgen.php
<?PHP
	/*
	Silentum PasswordGen v3.2
	Modified July 8, 2012
	passwordgen.php copyright 2006-2012 HyperSilence
	*/

	function generate_password($length, $pw_upper, $pw_lower, $pw_numbers, $pw_symbols, $pw_spaces) {
	$upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	$lower = "abcdefghijklmnopqrstuvwxyz";
	$number = "0123456789";
	$symbol = "!@#$%^&*()_+-=";
	$space = "     ";

	if($pw_upper) {
	$type_length += 26;
	$type .= $upper;
	}
	if($pw_lower) {
	$type_length += 26;
	$type .= $lower;
	}
	if($pw_numbers) {
	$type_length += 10;
	$type .= $number;
	}
	if($pw_symbols) {
	$type_length += 14;
	$type .= $symbol;
	}
	if($pw_spaces) {
	$type_length += 5;
	$type .= $space;
	}

	for($x=1; $x<=$length; $x++) {
	$password .= $type{rand(0,$type_length-1)};
	}

	return($password);
	}

	$checked = "checked=\"checked\" ";
	$selected = "selected=\"selected\" ";

	if($_GET["length"] == "") {
	$message = "Choose your password options below.";
	}
	elseif($_GET["lower"] == "" && $_GET["upper"] == "" && $_GET["numbers"] == "" && $_GET["symbols"] == "") {
	$message = "Choose your password options below.";
	}
	elseif($_GET["length"] > 50) {
	$message = "The maximum number of characters for a password is 50.";
	}
	elseif($_GET["length"] < 5) {
	$message = "A password should <b>never</b> be less than 5 characters.";
	}
	elseif($_GET["passwords"] == 1) {
	$message = generate_password($_GET["length"],$_GET["upper"],$_GET["lower"],$_GET["numbers"],$_GET["symbols"],$_GET["spaces"]);
	}
	elseif($_GET["passwords"] == 2) {
	$message = generate_password($_GET["length"],$_GET["upper"],$_GET["lower"],$_GET["numbers"],$_GET["symbols"],$_GET["spaces"])."<br><br>".generate_password($_GET["length"],$_GET["upper"],$_GET["lower"],$_GET["numbers"],$_GET["symbols"],$_GET["spaces"]);
	}
	elseif($_GET["passwords"] == 3) {
	$message = generate_password($_GET["length"],$_GET["upper"],$_GET["lower"],$_GET["numbers"],$_GET["symbols"],$_GET["spaces"])."<br><br>".generate_password($_GET["length"],$_GET["upper"],$_GET["lower"],$_GET["numbers"],$_GET["symbols"],$_GET["spaces"])."<br><br>".generate_password($_GET["length"],$_GET["upper"],$_GET["lower"],$_GET["numbers"],$_GET["symbols"],$_GET["spaces"]);
	}
	elseif($_GET["passwords"] == 4) {
	$message = generate_password($_GET["length"],$_GET["upper"],$_GET["lower"],$_GET["numbers"],$_GET["symbols"],$_GET["spaces"])."<br><br>".generate_password($_GET["length"],$_GET["upper"],$_GET["lower"],$_GET["numbers"],$_GET["symbols"],$_GET["spaces"])."<br><br>".generate_password($_GET["length"],$_GET["upper"],$_GET["lower"],$_GET["numbers"],$_GET["symbols"],$_GET["spaces"])."<br><br>".generate_password($_GET["length"],$_GET["upper"],$_GET["lower"],$_GET["numbers"],$_GET["symbols"],$_GET["spaces"]);
	}
	elseif($_GET["passwords"] == 5) {
	$message = generate_password($_GET["length"],$_GET["upper"],$_GET["lower"],$_GET["numbers"],$_GET["symbols"],$_GET["spaces"])."<br><br>".generate_password($_GET["length"],$_GET["upper"],$_GET["lower"],$_GET["numbers"],$_GET["symbols"],$_GET["spaces"])."<br><br>".generate_password($_GET["length"],$_GET["upper"],$_GET["lower"],$_GET["numbers"],$_GET["symbols"],$_GET["spaces"])."<br><br>".generate_password($_GET["length"],$_GET["upper"],$_GET["lower"],$_GET["numbers"],$_GET["symbols"],$_GET["spaces"])."<br><br>".generate_password($_GET["length"],$_GET["upper"],$_GET["lower"],$_GET["numbers"],$_GET["symbols"],$_GET["spaces"]);
	}
	elseif($_GET["passwords"] == "" || $_GET["passwords"] > 5 || $_GET["passwords"] < 1) {
	$message = "You can only generate 1-5 passwords at a time.";
	}
?>
<b>Generated Password(s)</b><br><br>
<?=$message?><br><br>
<form action="passwordgen.php" method="get">
	<table border="2" cellpadding="15" cellspacing="10">
		<tr>
			<td valign="top">
				<b>Password Type</b><br><br>
				<input <? if($_GET["lower"] == "1") echo $checked ?>name="lower" type="checkbox" value="1"> Lowercase letters<br>
				<input <? if($_GET["upper"] == "1") echo $checked ?>name="upper" type="checkbox" value="1"> Uppercase letters<br>
				<input <? if($_GET["numbers"] == "1") echo $checked ?>name="numbers" type="checkbox" value="1"> Numbers<br>
				<input <? if($_GET["symbols"] == "1") echo $checked ?>name="symbols" type="checkbox" value="1"> Symbols<br>
				<input <? if($_GET["spaces"] == "1") echo $checked ?>name="spaces" type="checkbox" value="1"> Spaces
			</td>
			<td valign="top">
				<b>Number of Characters</b><br><br>
				<select name="length">
					<option <? if($_GET["length"] == "5") echo $selected ?>value="5">5</option>
					<option <? if($_GET["length"] == "6") echo $selected ?>value="6">6</option>
					<option <? if($_GET["length"] == "7") echo $selected ?>value="7">7</option>
					<option <? if($_GET["length"] == "8") echo $selected ?>value="8">8</option>
					<option <? if($_GET["length"] == "9") echo $selected ?>value="9">9</option>
					<option <? if($_GET["length"] == "10") echo $selected ?>value="10">10</option>
					<option <? if($_GET["length"] == "11") echo $selected ?>value="11">11</option>
					<option <? if($_GET["length"] == "12") echo $selected ?>value="12">12</option>
					<option <? if($_GET["length"] == "13") echo $selected ?>value="13">13</option>
					<option <? if($_GET["length"] == "14") echo $selected ?>value="14">14</option>
					<option <? if($_GET["length"] == "15") echo $selected ?>value="15">15</option>
					<option <? if($_GET["length"] == "16") echo $selected ?>value="16">16</option>
					<option <? if($_GET["length"] == "17") echo $selected ?>value="17">17</option>
					<option <? if($_GET["length"] == "18") echo $selected ?>value="18">18</option>
					<option <? if($_GET["length"] == "19") echo $selected ?>value="19">19</option>
					<option <? if($_GET["length"] == "20") echo $selected ?>value="20">20</option>
					<option <? if($_GET["length"] == "21") echo $selected ?>value="21">21</option>
					<option <? if($_GET["length"] == "22") echo $selected ?>value="22">22</option>
					<option <? if($_GET["length"] == "23") echo $selected ?>value="23">23</option>
					<option <? if($_GET["length"] == "24") echo $selected ?>value="24">24</option>
					<option <? if($_GET["length"] == "25") echo $selected ?>value="25">25</option>
					<option <? if($_GET["length"] == "26") echo $selected ?>value="26">26</option>
					<option <? if($_GET["length"] == "27") echo $selected ?>value="27">27</option>
					<option <? if($_GET["length"] == "28") echo $selected ?>value="28">28</option>
					<option <? if($_GET["length"] == "29") echo $selected ?>value="29">29</option>
					<option <? if($_GET["length"] == "30") echo $selected ?>value="30">30</option>
					<option <? if($_GET["length"] == "31") echo $selected ?>value="31">31</option>
					<option <? if($_GET["length"] == "32") echo $selected ?>value="32">32</option>
					<option <? if($_GET["length"] == "33") echo $selected ?>value="33">33</option>
					<option <? if($_GET["length"] == "34") echo $selected ?>value="34">34</option>
					<option <? if($_GET["length"] == "35") echo $selected ?>value="35">35</option>
					<option <? if($_GET["length"] == "36") echo $selected ?>value="36">36</option>
					<option <? if($_GET["length"] == "37") echo $selected ?>value="37">37</option>
					<option <? if($_GET["length"] == "38") echo $selected ?>value="38">38</option>
					<option <? if($_GET["length"] == "39") echo $selected ?>value="39">39</option>
					<option <? if($_GET["length"] == "40") echo $selected ?>value="40">40</option>
					<option <? if($_GET["length"] == "41") echo $selected ?>value="41">41</option>
					<option <? if($_GET["length"] == "42") echo $selected ?>value="42">42</option>
					<option <? if($_GET["length"] == "43") echo $selected ?>value="43">43</option>
					<option <? if($_GET["length"] == "44") echo $selected ?>value="44">44</option>
					<option <? if($_GET["length"] == "45") echo $selected ?>value="45">45</option>
					<option <? if($_GET["length"] == "46") echo $selected ?>value="46">46</option>
					<option <? if($_GET["length"] == "47") echo $selected ?>value="47">47</option>
					<option <? if($_GET["length"] == "48") echo $selected ?>value="48">48</option>
					<option <? if($_GET["length"] == "49") echo $selected ?>value="49">49</option>
					<option <? if($_GET["length"] == "50") echo $selected ?>value="50">50</option>
				</select><br><br>
				<b>Number of Passwords to Generate</b><br><br>
				<select name="passwords">
					<option <? if($_GET["passwords"] == "1") echo $selected ?>value="1">1</option>
					<option <? if($_GET["passwords"] == "2") echo $selected ?>value="2">2</option>
					<option <? if($_GET["passwords"] == "3") echo $selected ?>value="3">3</option>
					<option <? if($_GET["passwords"] == "4") echo $selected ?>value="4">4</option>
					<option <? if($_GET["passwords"] == "5") echo $selected ?>value="5">5</option>
				</select>
			</td>
		</tr>
		<tr>
			<td colspan="2">
				<input type="submit" value="Generate Password(s)"><br><br>
				Powered by: <a href="http://hypersilence.com/silentum" title="Silentum PasswordGen v3.2">Silentum PasswordGen v3.2</a>
			</td>
		</tr>
	</table>
</form>
Return current item: PasswordGen