daily pastebin goal
38%
SHARE
TWEET

Untitled

a guest Jan 20th, 2017 112 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3.  
  4. header('Content-type: application/json');
  5. if($_POST) {
  6.     $username   = $_POST['username'];
  7.     $password   = $_POST['password'];
  8.  
  9.     if($username && $password) {
  10.  
  11.             $db_name     = 'jsonlogin';
  12.             $db_user     = 'root';
  13.             $db_password = '';
  14.             $server_url  = 'localhost';
  15.  
  16.             $mysqli = new mysqli('localhost', $db_user, $db_password, $db_name);
  17.  
  18.             /* check connection */
  19.             if (mysqli_connect_errno()) {
  20.                 error_log("Connect failed: " . mysqli_connect_error());
  21.                 echo '{"success":0,"error_message":"' . mysqli_connect_error() . '"}';
  22.             } else {
  23.                 if ($stmt = $mysqli->prepare("SELECT username FROM users WHERE username = ? and password = ?")) {
  24.  
  25.                     $password = md5($password);
  26.  
  27.                     /* bind parameters for markers */
  28.                     $stmt->bind_param("ss", $username, $password);
  29.  
  30.                     /* execute query */
  31.                     $stmt->execute();
  32.  
  33.                     /* bind result variables */
  34.                     $stmt->bind_result($id);
  35.  
  36.                     /* fetch value */
  37.                     $stmt->fetch();
  38.  
  39.                     /* close statement */
  40.                     $stmt->close();
  41.                 }
  42.  
  43.                 /* close connection */
  44.                 $mysqli->close();
  45.  
  46.                 if ($id) {
  47.                     error_log("User $username: password match.");
  48.                     echo '{"success":1}';
  49.                 } else {
  50.                     error_log("User $username: password doesn't match.");
  51.                     echo '{"success":0,"error_message":"Invalid Username/Password"}';
  52.                 }
  53.             }
  54.     } else {
  55.         echo '{"success":0,"error_message":"Invalid Username/Password."}';
  56.     }
  57. }else {
  58.     echo '{"success":0,"error_message":"Invalid Data."}';
  59. }
  60. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top