Advertisement
Guest User

Untitled

a guest
Aug 17th, 2016
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.26 KB | None | 0 0
  1. <?php
  2. string base64_decode ( string $str )
  3.     $licence = substr(base64_decode($_POST["licence"]), 0, -8);
  4.     $hwid = substr(base64_decode($_POST["hwid"]), 0, -8);
  5.     $db_user = "u155468569_admin";
  6.     $db_name = "u155468569_kappa";
  7.     $db_host = "mysql.hostinger.co.uk";
  8.     $db_pass = "11233240";
  9.     if (isset($licence) == false) {
  10.         echo("bad");
  11.         return;
  12.     }
  13.     if (isBadInput($licence) or isBadInput($hwid)) {
  14.         echo("bad");
  15.         return;
  16.     }
  17.    
  18.     if (checkAuth()) {
  19.         echo("ok");
  20.     } else {
  21.         echo("bad");
  22.     }
  23.     return;
  24.     function checkAuth() {
  25.         if (checkLic()) {
  26.             if (needNewHWID()) {
  27.                 setHwid();
  28.                 return true;
  29.             }
  30.             if (checkHwid()) {
  31.                 return true;
  32.             }
  33.         }
  34.         return false;
  35.     }
  36.     function checkLic() {
  37.         // Create connection
  38.         $conn = mysqli_connect("$db_host", "$db_user", "$db_pass", "$db_name");
  39.         // Check connection
  40.         if ($conn->connect_error) {
  41.             die("Connection failed: " . $conn->connect_error);
  42.         }
  43.         if ($verify = $conn->prepare("SELECT * FROM users WHERE licence=?")) {
  44.             $verify->bind_param('s', $licence);
  45.             $verify->execute();
  46.             $result = $verify->get_result();
  47.             if ($result->num_rows > 0) {
  48.                 while ($row = $result->fetch_assoc()) {
  49.                     if ($row["licence"] == $licence) {
  50.                         return true;
  51.                     }
  52.                 }
  53.             }
  54.         }
  55.         $conn->close();
  56.         return false;
  57.     }
  58.     function checkHwid() {
  59.         // Create connection
  60.         $conn = new mysqli($db_name, $db_user, $db_pass, $db_name);
  61.         // Check connection
  62.         if ($conn->connect_error) {
  63.             die("Connection failed: " . $conn->connect_error);
  64.         }
  65.         if ($verify = $conn->prepare("SELECT hwid FROM users WHERE hwid=?")) {
  66.             $verify->bind_param('s', $hwid);
  67.             $verify->execute();
  68.             $result = $verify->get_result();
  69.             if ($result->num_rows > 0) {
  70.                 while ($row = $result->fetch_assoc()) {
  71.                     if ($row["hwid"] == $hwid) {
  72.                         return true;
  73.                     }
  74.                 }
  75.             }
  76.         }
  77.         $conn->close();
  78.         return false;
  79.     }
  80.     function setHWID() {
  81.         // Create connection
  82.         $conn = new mysqli($db_name, $db_user, $db_pass, $db_name);
  83.         // Check connection
  84.         if ($conn->connect_error) {
  85.             die("Connection failed: " . $conn->connect_error);
  86.         }
  87.         if ($verify = $conn->prepare("UPDATE users SET hwid = ? WHERE licence=?")) {
  88.             if (isset($verify) == false) {
  89.                 $conn->close();
  90.                 return false;
  91.             }
  92.        
  93.             $verify->bind_param('ss', $hwid, $licence);
  94.             $verify->execute();
  95.         }
  96.         $conn->close();
  97.     }
  98.     function needNewHWID() {
  99.         // Create connection
  100.         $conn = new mysqli($db_name, $db_user, $db_pass, $db_name);
  101.         // Check connection
  102.         if ($conn->connect_error) {
  103.             die("Connection failed: " . $conn->connect_error);
  104.         }
  105.         if ($verify = $conn->prepare("SELECT hwid FROM users WHERE licence=?")) {
  106.             $verify->bind_param('s', $licence);
  107.             $verify->execute();
  108.             $result = $verify->get_result();
  109.             if ($result->num_rows > 0) {
  110.                 while ($row = $result->fetch_assoc()) {
  111.                     if ($row["hwid"] == "notset") {
  112.                         return true;
  113.                     }
  114.                 }
  115.             }
  116.         }
  117.         $conn->close();
  118.         return false;
  119.     }
  120.     function isBadInput() {
  121.         string $input;
  122.         if (strlen($input) > 30) {
  123.             return true;
  124.         }
  125.         if (strpos(strtolower($input), 'where') !== false or
  126.             strpos(strtolower($input), 'insert into') !== false or
  127.             strpos(strtolower($input), 'from') !== false or
  128.             strpos(strtolower($input), 'update') !== false or
  129.             strpos(strtolower($input), 'set') !== false) {
  130.                 return true;
  131.         }
  132.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement