Last active
March 10, 2016 21:56
-
-
Save lukasni/d3ba2345134ff4e5c805 to your computer and use it in GitHub Desktop.
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 | |
// Password generator function | |
function passwordGen($num, $length, $inclBigLetters = true, $inclSmallLetters = true, $inclNumbers = true, $inclSpecialChars = false) { | |
$bigLetters = array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"); | |
$smallLetters = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"); | |
$numbers = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); | |
$specialChars = array("$", "_", "+", "-", "/", "*", "=", "(", ")"); | |
$result = array(); | |
$characterSet = array(); | |
if ($inclSmallLetters) { $characterSet = array_merge($characterSet, $smallLetters);} | |
if ($inclBigLetters) { $characterSet = array_merge($characterSet, $bigLetters);} | |
if ($inclNumbers) { $characterSet = array_merge($characterSet, $numbers);} | |
if ($inclSpecialChars) { $characterSet = array_merge($characterSet, $specialChars);} | |
for ($i = 0; $i < $num; $i++) { | |
$text = ""; | |
for ($chars = 0; $chars < $length; $chars++) { | |
$text .= $characterSet[random_int(0,count($characterSet)-1)]; | |
} | |
$result[] = $text; | |
} | |
return $result; | |
} | |
// Testing | |
$test = passwordGen(5,32); | |
var_dump($test); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment