<?php
function generate_password($minlen=5, $maxlen=8, $mixedcase=false, $punctuation=false) {
$pwchars = 'bdfghjklmnprstvwyz23456789';
$vowels = 'aeiouyaeiou';
if ($mixedcase) {
$pwchars .= 'BDFGHJKLMNPRSTVWYZ23456789';
$vowels .= 'AEUYAEU';
}
else {
$vowels .= '0'; // number 0
}
if ($punctuation) {
$pwchars .= '$.$.$.';
$vowels .= '!@-_!@-_';
}
$pwchars = preg_split('//', $pwchars, -1, PREG_SPLIT_NO_EMPTY);
$vowels = preg_split('//', $vowels, -1, PREG_SPLIT_NO_EMPTY);
shuffle($pwchars);
shuffle($vowels);
$cmax = count($pwchars) - 1;
$vmax = count($vowels) - 1;
$pwlen = mt_rand($minlen, $maxlen);
while ($pwlen-- > 0) {
$pw .= $pwchars[mt_rand(0, $cmax)];
$pw .= $vowels[mt_rand(0, $vmax)];
--$pwlen;
}
return $pw;
}
if (isset($_GET['minlen'])) {
$password = generate_password(intval($_GET['minlen']), intval($_GET['maxlen']), intval($_GET['mixedcase']), intval($_GET['punctuation']));
$password = "<code><strong style='font-size:larger'>Generated password: $password</strong></code>";
}
else {
$_GET['minlen'] = 5;
$_GET['maxlen'] = 8;
$_GET['mixedcase'] = 0;
$_GET['punctuation'] = 0;
$password = '';
}
$mcchecked = isset($_GET['mixedcase']) && intval($_GET['mixedcase']) > 0 ? ' checked="checked"' : '';
$pchecked = isset($_GET['punctuation']) && intval($_GET['punctuation']) > 0 ? ' checked="checked"' : '';
echo $password."
<form action=\"/files/pwgen.php\" method=\"get\">
<div class='field'><label for='idminlen'>Minimum Password Length:</label><input type='text' name='minlen' id='idminlen' value=\"".intval($_GET['minlen'])."\" /></div>
<div class='field'><label for='idmaxlen'>Maximum Password Length:</label><input type='text' name='maxlen' id='idmaxlen' value=\"".intval($_GET['maxlen'])."\" /></div>
<div class='field'><label for='idmixedcase'>Mixed Case:</label><input type='checkbox' name='mixedcase' id='idmixedcase'$mcchecked value='1' /></div>
<div class='field'><label for='idpunctuation'>Punctuation:</label><input type='checkbox' name='punctuation' id='idpunctuation'$pchecked value='1' /></div>
<div class='field'><input type='submit' name='submit' value='Generate Password' /></div>
</form>
";
echo "<code>";
highlight_string(file_get_contents(__FILE__));
echo "</code>";