function commit_post($text, $jsCrypt, $lifetime_seconds, $short = false) { do { $urlKey = PasswordGenerator::getAlphaNumericPassword($short ? 8 : 22); } while (retrieve_post($urlKey) !== false); $id = get_database_id($urlKey); $encryptionKey = get_encryption_key($urlKey); $iv = mcrypt_create_iv(IV_BYTES, MCRYPT_DEV_URANDOM); $encrypted = SafeEncode($iv . mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $encryptionKey, $text, MCRYPT_MODE_CBC, $iv)); $jsCrypted = $jsCrypt ? 1 : 0; $time = (int) (time() + $lifetime_seconds); mysql_query("INSERT INTO pastes (token, data, time, jscrypt) \n VALUES('{$id}', '{$encrypted}', '{$time}', '{$jsCrypted}')"); return $urlKey; }
$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."); } if (preg_match("/^[!-~]{64}\$/", $ascii) !== 1) {