"; */ ini_set('display_errors', '1'); error_reporting(E_ALL & ~E_NOTICE); ini_set('display_startup_errors', '1'); ini_set('track_errors', '1'); // predefines $debug = 'off'; // [off|on]. $chars = ''; $space = ''; $alphahexonly = ''; $customchars = ''; $debugchecked = ''; // fix for PHP 8.0 warning "PHP Warning: Undefined array key ..." $array_keys_used = array("numbers29", "numbers09", "upper_letters", "lower_letters", "special", "special_websafe", "highascii", "ambiguous", "space", "alphahexonly", "numpass", "numchar", "numpass", "format", "customchars", "debug", "extra"); foreach($array_keys_used as $thiskey){ if(!isset($_REQUEST[$thiskey])){ $_REQUEST[$thiskey] = ''; }; }; #if (empty($_REQUEST['debug'])){ $_REQUEST['debug'] = ''; }; #if (empty($_REQUEST['extra'])){ $_REQUEST['extra'] = ''; }; // phpinfo(); mb_regex_encoding('UTF-8'); mb_internal_encoding("UTF-8"); if ($_REQUEST['debug'] == "on"){ $debug = 'on'; }else{ $debug = 'off'; }; $cps = load_code_points(); if ($debug == 'on'){ print "
" . print_r($_REQUEST, TRUE) . "
"; }; // If this hasn't been used, all checked values will be null. Populate them in a friendly fashion. if ( (empty($_REQUEST['numchar'])) && (empty($_REQUEST['numbers09'])) && (empty($_REQUEST['numbers29'])) && (empty($_REQUEST['upper_letters'])) && (empty($_REQUEST['lower_letters'])) && (empty($_REQUEST['special'])) && (empty($_REQUEST['special_websafe'])) && (empty($_REQUEST['highascii'])) && (empty($_REQUEST['ambiguous'])) && (empty($_REQUEST['format'])) && (empty($_REQUEST['space'])) && (empty($_REQUEST['alphahexonly'])) && (empty($_REQUEST['customchars'])) ){ $numchar = "24"; $numpass = "20"; $numbers29 = "checked"; $numbers09 = ""; $upper_letters = "checked"; $lower_letters = "checked"; $special = ""; $special_websafe = "checked"; $ambiguous = ""; $highascii = ""; $format_form = "checked"; $debug = ""; }else{ // reinforce limits. if (intval($_REQUEST['numpass']) >= 50){ $numpass = 50; }; // more may slow the page render down on mobile devices. if (intval($_REQUEST['numchar']) >= 1 ){ $numchar = $_REQUEST['numchar']; }else{ $numchar = 8; }; if (intval($_REQUEST['numpass']) >= 1 ){ $numpass = $_REQUEST['numpass']; }else{ $numpass = 8; }; // checkboxes if ($_REQUEST['numbers29'] == "on"){ $numbers29 = "checked"; }else{ $numbers29 = ''; }; if ($_REQUEST['numbers09'] == "on"){ $numbers09 = "checked"; }else{ $numbers09 = ''; }; if ($_REQUEST['upper_letters'] == "on"){ $upper_letters = "checked"; }else{ $upper_letters = ''; }; if ($_REQUEST['lower_letters'] == "on"){ $lower_letters = "checked"; }else{ $lower_letters = ''; }; if ($_REQUEST['special'] == "on"){ $special = "checked"; }else{ $special = ''; }; if ($_REQUEST['special_websafe'] == "on"){$special_websafe = "checked"; }else{ $special_websafe = ''; }; if ($_REQUEST['highascii'] == "on"){ $highascii = "checked"; }else{ $highascii = ''; }; if ($_REQUEST['ambiguous'] == "on"){ $ambiguous = "checked"; }else{ $ambiguous = ''; }; if ($_REQUEST['space'] == "on"){ $space = "checked"; }else{ $space = ''; }; if ($_REQUEST['alphahexonly'] == "on"){ $alphahexonly = "checked"; }else{ $alphahexonly = ''; }; if ($_REQUEST['debug'] == "on"){ $debugchecked = "checked"; }else{ $debugchecked = ''; }; if ($_REQUEST['format'] == "form"){ $format_form = "checked"; $format_text = ""; }elseif($_REQUEST['format'] == "text"){ $format_form = ""; $format_text = "checked"; }else{ $format_form = "checked"; $format_text = ""; }; }; if (isset($_REQUEST['customchars'])){ $customchars = $_REQUEST['customchars']; }; if ($numbers09 == "checked"){ $chars .= "0123456789"; }; if ($numbers29 == "checked"){ if ($ambiguous == "checked"){ $chars .= "01"; }; $chars .= "23456789"; }; if ($upper_letters == "checked"){ $chars .= "ABCDEFGHJKMNPQRSTUVWXYZ"; if ($ambiguous == "checked"){ $chars .= "ILO"; }; }; if ($lower_letters == "checked"){ $chars .= "abcdefghjkmnpqrstuvwxyz"; if ($ambiguous == "checked"){ $chars .= "ilo"; }; }; if ($special == "checked"){ $chars .= "!@#%^&*()_+-=[]{}|;:<>?/.,~`\'\"\$"; if ($ambiguous == "checked"){ # Unused in this context. }; }; if ($special_websafe == "checked"){ $chars .= "!@^*()_+-=[]{}|;:.,~"; if ($ambiguous == "checked"){ # Unused in this context. }; }; if (isset($customchars)){ $chars .= $customchars; }; if ($highascii == "checked"){ for ($i=161; $i<=255; $i++){ // $showcurchar = urlencode(chr($i)); // $showcurchar = mb_convert_encoding(chr($i), 'HTML-ENTITIES', "UTF-8"); // $showcurchar = htmlentities(chr($i), ENT_QUOTES, 'cp1252'); // $showcurchar = htmlentities(chr($i), ENT_QUOTES, 'UTF-8'); // $showcurchar = htmlentities(html_entity_decode(chr($i), ENT_COMPAT,'ISO-8859-1')); $html_char = "&#$i;"; $char = mb_convert_encoding("$html_char", 'UTF-8', 'HTML-ENTITIES' ); if ($debug == 'on'){ print "High Ascii Adding $i - " . $char . "
\n"; }; $chars .= $char; }; if ($ambiguous == "checked"){ # Unused in this context. }; }; if (is_array($_REQUEST['extra'])){ foreach ($_REQUEST['extra'] as $key => $val){ $extra[$key] = "checked"; if ($debug == 'on'){ print "Lang: $key
\n"; }; if ($debug == 'on'){ print "Range: " . $cps[$key]['start'] ."-". $cps[$key]['end'] . "
\n"; }; for ($i=$cps[$key]['start']; $i<= $cps[$key]['end']; $i++){ $html_char = "&#$i;"; $char = mb_convert_encoding("$html_char", 'UTF-8', 'HTML-ENTITIES' ); $chars .= $char; }; }; }; if ($space == "checked"){ $chars .= " "; }; if ($alphahexonly == "checked"){ $chars = "0123456789abcdef"; }; if (!$chars){ // If we want ambiguous characters only, this has to be checked. if ($ambiguous == "checked"){ $chars .= "10ILOilo"; }; }; // We're moving these around a little, so we'll have a unique string of characters, // just in case the user selected options which would cause duplicates, // such as numbers29 and numbers09 //$disp_charset = $chars; // // $disp_charset = preg_replace("/([^\s]{14})/","$1 ",$disp_charset); //$disp_charset = preg_split('/(?
" . print_r($disp_charset, TRUE) . "
"; // // $disp_charset = htmlentities($disp_charset, ENT_HTML5, "UTF-8"); if ($debug == 'on'){ print "
\$chars
" . print_r($chars, TRUE) . "
"; }; $chararray = preg_split('/(?\$chararray
" . print_r($chararray, TRUE) . "
"; }; $chararray = array_unique($chararray, SORT_REGULAR); if ($debug == 'on'){ print "
After uniq and sort
" . print_r($chararray, TRUE) . "
"; }; $chars = join("", $chararray); if ($debug == 'on'){ print "
\$chars after join
" . print_r($chars, TRUE) . "
"; }; $disp_charset = join(" ", $chararray); if ($debug == 'on'){ print "
Final \$disp_charset
" . print_r($chars, TRUE) . "
"; }; if (!isset($format_text)){ $format_text = ''; }; if (!isset($format_form)){ $format_form = ''; }; print "
This script generates (possibly) strong passwords

Number of characters Please use at least 8
Number of passwords Make one or a list of X
Characters to use:
Numbers 2-9: 23456789
Numbers 0-9: 0123456789
Uppercase Letters: A-Z except ILO
Lowercase Letters: a-z except ilo
Special Characters: !@#%^&*()_+-=[]{}|;:<>?/.,~`
Special Characters (websafe): !@^*()_+-=[]{}|;:.,~
Ambiguous Characters: 10,ILO, and/or ilo removed from above
Space: (the space character)
\"High ASCII\" Characters: ASCII ¡ (161) through ÿ (255). Accents, umlats, misc
AlphaHex ONLY *only* \"0123456789abcdef\".
This overrides all other options.
Debug mode?: This makes the page show more information.
You probably don't want it.
Custom character list.
No delimiting required.
Format: Box Text
Character Set: $disp_charset
"; $charlist = preg_split("//u", $chars, -1, PREG_SPLIT_NO_EMPTY); $disp_size = count($charlist); $list_size = $disp_size - 1; if ($list_size < 1){ print "0"; }; print "
"; print "Requested Length: $numchar
\n"; print "Number of possible characters: $disp_size characters
\n"; print "Strength: " . pow($disp_size, $numchar) . "
\n"; print "Number of passwords to generate: $numpass
\n"; print "
"; if ($disp_size < 1){ print "You must use at least one character set. Please select one and try again.
\n"; print "
"; print "
"; print "
"; include_once("../../footer.php"); exit; }; print ""; if ($format_form){ print ""; }else{ print "\n"; }else{ print "$thispass
\n"; }; }; if ($format_form){ // }else{ print "
  Password
"; }; // Scale the result box by the number of characters plus a little. // The font is 12px, so we're rescaling it by 14px. $resultboxsize = ($numchar * 9) + 12; $pcount = 0; while ($pcount < $numpass){ $pcount++; $thispass = generate_password($numchar, $chars); // $fieldsize = $numchar+2; // This is our old box scaling. if ($format_form){ // class='results' // Our old input result box. // print "
$pcount of $numpass
"; }; print "
"; print " Extra Character Sets.
Not all work on all systems.
No attempt is made to remove ambiguous characters from these.

Select All | None

(\"All\" is disabled. There are too many characters. Your browser would crash.)


"; ksort($cps); foreach ($cps as $key => $val){ // "" was removed from the line below. It didn't have a function anyways. if (isset($key) && isset($val)){ #print " $key " . $cps[$key]['hexstart'] . "-" . $cps[$key]['hexend'] . "
\n"; if(!isset($extra[$key])){ $extra[$key] = ''; // fix for "Undefined array key" error on next line. PHP8 cares. PHP7 didn't. }; print " $key " . $cps[$key]['hexstart'] . "-" . $cps[$key]['hexend'] . "
\n"; }; }; // Assemble the link for this file, to give to validator.w3.org $melink = "$_SERVER[REQUEST_SCHEME]://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; print "

You can learn from this code. It requires these two files.
All the password generation is done on the server side. It is recommended to only generate passwords over a https connection, and from an on-site server that is properly secured. "; // This is also just for my site. include_once("../../footer.php"); function generate_password($numchar, $chars){ $charlist = preg_split("//u", $chars, -1, PREG_SPLIT_NO_EMPTY); $disp_size = count($charlist); $list_size = $disp_size - 1; if ($list_size < 1){ print "0"; }; $result = ''; for ($i=0; $i<$numchar; $i++) { $thischar = intval(rand(0,$list_size)); $result .= $charlist[$thischar]; }; return ($result); }; function load_code_points(){ $raw = explode("\n", (file_get_contents("Blocks.txt"))); foreach ($raw as $curline){ $curline = ltrim(rtrim($curline)); if (($curline != '') && (strpos("$curline", "#") === FALSE)){ #if ($debug == 'on'){ print "Loading CP LINE: $curline
\n"; }; list ($prange, $name) = explode(";", $curline); #if ($debug == 'on'){ print "Name: $name Range: $prange\n
"; }; if (($name) && (strpos("$curline", "#") === FALSE)){ $name = ltrim(rtrim($name)); list ($start_hex, $foo, $end_hex) = explode(".", $prange); $cp[$name]['hexstart'] = $start_hex; $cp[$name]['hexend'] = $end_hex; $cp[$name]['start'] = hexdec($start_hex); $cp[$name]['end'] = hexdec($end_hex); }; }; }; return($cp); }; ?>