Advertisement
qiTsuk

Awesome Login!!

Mar 10th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.86 KB | None | 0 0
  1. <?php
  2. $con=mysqli_connect('host', 'username', 'password', 'db_name');
  3. $key = "supaaaasecretkey!!";
  4.  
  5.  
  6.  
  7. if ($con->connect_errno) {
  8.     echo json_encode('Connect failed: ', $con->connect_error);
  9. }
  10.  
  11. $rowResult = "";
  12. $un = $_GET['un'];
  13. $pw = $_GET['pw'];
  14. $password = $_GET['password'];
  15. if ($result = $con->query("SELECT password FROM Users WHERE username='{$un}'")) {
  16.   while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
  17.     $row['password'] = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($row['password']), MCRYPT_MODE_CBC, md5(md5($key))), "\0");
  18.     $rowResult = $row['password'];
  19.   }
  20.     if (strcmp($pw, $rowResult) !== 0) {
  21.         $result = ["loginSuccess" => "false"];
  22.         echo json_encode($result);
  23.     } else if (strcmp($pw, $rowResult) === 0) {
  24.         $result = ["loginSuccess" => "true"];
  25.         echo json_encode($result);
  26.     }
  27. }
  28. mysqli_close($con);
  29. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement