Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class APIKey {
- public static function createKey() {
- $key = null;
- do {
- sprintf('%04X%04X%04X%04X%04X%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
- } while (self::validateKey($key));
- }
- public static function validateKey($key) {
- $stmt = Database::$db->prepare("SELECT COUNT(*) FROM APIKEY WHERE uuid = ?");
- $stmt->execute(array($key));
- return ($stmt->fetch()[0] > 0);
- }
- }
- $key = APIKey::createKey();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement