123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- <?php
- header('Content-type: application/json');
- if ($_SERVER["REQUEST_METHOD"] == "POST") {
-
- $json = json_decode(file_get_contents('php://input'), true);
-
-
- $username = $json["username"];
- $password = $json["password"];
- if(strlen($username) == 0 or strlen($password) == 0){
- header("400 Bad Request", true, 400);
- exit();
- }
-
- include 'db.php';
-
-
- $sql = "SELECT hash FROM login WHERE username = '".$username."'";
- $result = $conn->query($sql);
- if($result->num_rows){
- $result = $result->fetch_assoc();
- $hash = $result["hash"];
- } else {
- $conn->close();
- header("400 Bad Request", true, 400);
- exit();
- }
-
-
- if(!password_verify($password, $hash)){
- $conn->close();
- header("400 Bad Request", true, 400);
- exit();
- }
-
-
- $conn->close();
- header("200 OK", true, 200);
- exit();
-
- } else {
- header($_SERVER["SERVER_PROTOCOL"]." 405 Method Not Allowed", true, 405);
- exit();
- }
- ?>
|