<?php

        // set up some parameters that APG will take and just glomp any invalid input

        // num_of_pass:

        //      number of passwords to generate

        //      must be integer from 1 to 1024 (arbitrary max, APG supports more)

        //      default 6

        $num_of_pass = intval($_GET['num_of_pass']);

        if ( $num_of_pass < 1 || $num_of_pass > 1024)

                $num_of_pass = 6;

        // min_pass_len:

        //      generate minimum password length

        //      must be integer from 1 to 256 (arbitrary max, APG supports more)

        //      default 8

        $min_pass_len = intval($_GET['min_pass_len']);

        if ( $min_pass_len < 1 || $min_pass_len > 256)

                $min_pass_len = 8;

        // max_pass_len:

        //      generate maximum password length

        //      must be integer from 1 to 256 (arbitrary max, APG supports more)

        //      default 8

        $max_pass_len = intval($_GET['max_pass_len']);

        if ( $max_pass_len < $min_pass_len || $max_pass_len > 256)

                $max_pass_len = 10;

?>

<html>

        <head>

                <title>Password Generator</title>

        </head>

        <body>

                <p>This page generates random passwords with APG. Use the following form to give APG arguments.</p>

        <form action="<?php echo $_SERVER[‘PHP_SELF’]; ?>">

                <table>

                        <tr><td>Number of passwords:</td><td><input type="text" name="num_of_pass" value="<?php echo $num_of_pass ?>" /></td></tr>

                        <tr><td>Minimum length:</td><td><input type="text" name="min_pass_len" value="<?php echo $min_pass_len ?>" /></td></tr>

                        <tr><td>Maximum length:</td><td><input type="text" name="max_pass_len" value="<?php echo $max_pass_len ?>" /></td></tr>

                        <tr><td colspan="2"><input type="submit" /></td></tr>

                </table>

        </form>

<pre>

<?php

        nl2br(system("apg -n $num_of_pass -m $min_pass_len -x $max_pass_len -t"));

 ?>

</pre>

        </body>

</html>