<?php 
$limit 
16;

$page_title 'Password Generator';
include (
'./includes/header.html');

?>

<h2>Password Generator</h2>
<p>This script will produce a Password of <?php echo $limit?> characters long. <br />
Continue generating a Password until you find one that suits your needs.<br />
<form action="index.php" method="post">
    <p>Select a Password length from the Select box. Defaults to 16 characters.</p>
        <select name="limit">
        <option value="8">8 characters</option>
        <option value="16 characters" selected="selected">16</option>
        <option value="24">24 characters</option>
        <option value="32">32 characters</option>
        <option value="64">64 characters</option>
        <option value="128">128 characters</option>
    </select></p>
 
    <p>Checkbox for Password strictness (security level)</p>
    <input type="radio" name="sec" value="0"> Good (Numeric and Lower-case Alpha)
    <input type="radio" name="sec"  checked="checked" value="1"> Better (adds Upper-case Alpha)
    <input type="radio" name="sec" value="2"> Best (adds Special Characters)
       <p><input type="submit" name="submit" value="Generate Password ?" /></p>
    <input type="hidden" name="submitted" value="TRUE" />
</form>
<?php
// Check if the form has been submitted.
if (isset($_POST['submitted'])) {

// define the starting array and the output variable
echo $sec '<br />';
if ( 
$_POST[sec] < ) { 
    
$input = array( '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' );
    } elseif (
$_POST[sec] < 2){ 
      
$input = array( '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' );
      } 
      else {
        
$input = array( '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z''!','@','#','$','*','_','+','=','-','{','}','[',']',':','?' );
        }
$i=0;
if ( 
count($input) < ($_POST['limit'] )) {
while ( 
count($input) < ($_POST['limit'] +10 )) {
         
            
array_push$input$input[$i]);
        
$i++;
    }
}

// randomize the array of values
    
shuffle($input);

    
// declare an empty output string 
$out $input[0];

// loop through the required number of array values, concatenate the value to the output variable
for ($i 1$i < ($_POST['limit']) ; $i++) {
    
$out .= $input[$i];
}

// output the $output here
echo '<textarea >' $out '</textarea>';
?>
<p>Cut (Control C) and Paste (Control V) the Password and test its strength using the link found below.</p>

<p>Test the strength of your new <?php echo $_POST['limit']; ?> character Password <a href="http://www.microsoft.com/protect/yourself/password/checker.mspx" title="Password Checker" >here</a></p>
<?php
// End of the main Submit conditional.
include ('./includes/footer.html');
?>