public function create($min_length = 10, $max_length = null, $characters = null) { $min_length = (int) $min_length; if ($min_length < 4) { $min_length = 4; } if ($max_length === null) { $max_length = $min_length; } else { $max_length = (int) $max_length; if ($max_length < $min_length) { $max_length = $min_length; } } $length = mt_rand($min_length, $max_length); $characters = (string) $characters; if ($characters == '') { $characters = "!#\$%+-0123456789=?@ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; } return PasswordGenerator::getCustomPassword(str_split($characters), $length); }
$hex_chars = array_merge($hex_chars, str_split($hex)); $custom_chars = array_merge($custom_chars, str_split($custom)); } $ascii_chars = array_unique($ascii_chars); $alpha_chars = array_unique($alpha_chars); $hex_chars = array_unique($hex_chars); $custom_chars = array_unique($custom_chars); if (count($ascii_chars) !== 94) { failTest("Not all ASCII chars are included."); } if (count($alpha_chars) !== 62) { failTest("Not all AlphaNumeric chars are included."); } if (count($hex_chars) !== 16) { failTest("Not all Hex chars are included."); } if (count($custom_chars) !== 2) { failTest("Not all Custom chars are included."); } if (PasswordGenerator::getCustomPassword("abc", 64) !== false) { failTest("Improper usage does not return false."); } for ($i = 0; $i < 1000; $i++) { $ints = PasswordGenerator::getRandomInts($i); $count = count($ints); if ($count != $i) { failTest("{$i} random ints is {$count} and not {$i}"); } } echo "ALL TESTS PASS!\n"; exit(0);