Last active
August 19, 2021 13:20
-
-
Save bendiy/5688443 to your computer and use it in GitHub Desktop.
PHP xkcd password generator for *nix systems
This file contains 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 | |
/* | |
* Generate xkcd style password from /usr/share/dict/words | |
* | |
* http://xkcd.com/936/ | |
* apt-get install wamerican | |
*/ | |
function xkcd_password_generator() { | |
$lines = file('/usr/share/dict/words', FILE_IGNORE_NEW_LINES); | |
$length = count($lines); | |
$pw = ''; | |
for ($i = 1; $i <= 4; $i++) { | |
$plain = FALSE; | |
while (!$plain) { | |
// Get random word from $lines | |
$key = mt_rand(0, $length); | |
if ((preg_match("/^[a-z]+$/", $lines[$key]) == 1) && (strlen($lines[$key]) < 9)) { | |
// String only contains a to z characters | |
$plain = TRUE; | |
$pw = $pw . $lines[$key]; | |
} | |
} | |
} | |
return $pw; | |
} | |
echo xkcd_password_generator() . "\n"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cheers just what I needed