Ejemplo n.º 1
0
function generateSecurePassword($length)
{
    $ascii = PasswordGenerator::getASCIIPassword($length);
    return $ascii;
}
Ejemplo n.º 2
0
$hex = PasswordGenerator::getHexPassword(64);
$alpha = PasswordGenerator::getAlphaNumericPassword(64);
$custom = PasswordGenerator::getCustomPassword(array('a', 'b'), 64);
echo $ascii, "\n", $hex, "\n", $alpha, "\n", $custom, "\n\n";
function failTest($msg)
{
    echo "FAILED: {$msg}\n";
    exit(1);
}
$last = array();
$ascii_chars = array();
$alpha_chars = array();
$hex_chars = array();
$custom_chars = array();
for ($i = 0; $i < 20; $i++) {
    $ascii = PasswordGenerator::getASCIIPassword(64);
    $alpha = PasswordGenerator::getAlphaNumericPassword(64);
    $hex = PasswordGenerator::getHexPassword(64);
    $custom = PasswordGenerator::getCustomPassword(array('a', 'b'), 64);
    if (in_array($ascii, $last)) {
        failTest("Duplicate ASCII password.");
    }
    if (in_array($alpha, $last)) {
        failTest("Duplicate AlphaNumeric password.");
    }
    if (in_array($hex, $last)) {
        failTest("Duplicate Hex password.");
    }
    if (in_array($custom, $last)) {
        failTest("Duplicate Custom password.");
    }