Created
September 19, 2012 20:23
-
-
Save hcooper/3752009 to your computer and use it in GitHub Desktop.
PHP script to generate random passwords via apg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /* PHP script using apg to generate random passwords | |
| * | |
| * Requires: apg | |
| * Suggested: rng-tools (to keep entropy high) | |
| * | |
| * Stick this in your apache/htaccess to support custom lengths | |
| * via domain.com/12 | |
| * | |
| * RewriteEngine on | |
| * RewriteRule ^/([0-9]{1,3})$ /index.php?length=$1 [L] | |
| * | |
| * Hereward Cooper - Sometime 2010 */ | |
| $length = $_GET['length']; | |
| if ($length == "") { | |
| $length = "8"; /* Our default length */ | |
| } elseif ($length < "3") { | |
| $length = "3"; /* Min length APG will accept */ | |
| } elseif ($length > "255") { | |
| $length = "255"; /* Max length APG will accept */ | |
| } | |
| /* Crude input validation */ | |
| if (!is_numeric($length)) { | |
| die(); | |
| } | |
| /* APG flags: | |
| * -n1 output one password | |
| * -E exclude ambigious letters (0I10) | |
| * -a0 produce pronouncable passwords | |
| * -m min length | |
| * -x max length | |
| * -MNCL must have numbers, upper and lower case | |
| */ | |
| system('/usr/bin/env apg -n1 -EOI10 -a0 -m '.$length.' -x '.$length.' -MNCL', $return); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment