getConnection(); $data = json_decode(file_get_contents("php://input")); $email = trim($data->email); $password = trim($data->password); $query = "SELECT id, first_name, last_name, password FROM users WHERE email = :email LIMIT 0,1"; $stmt = $conn->prepare( $query ); $stmt->bindParam(':email', $email); $stmt->execute(); $num = $stmt->rowCount(); if($num > 0) { $row = $stmt->fetch(PDO::FETCH_ASSOC); $id = $row['id']; $firstname = $row['first_name']; $lastname = $row['last_name']; $password2 = $row['password']; if(password_verify($password, $password2)) { $token = array( "iss" => $CONF['CLAIM']['ISSUER'], "aud" => $CONF['CLAIM']['AUDIENCE'], "iat" => $CONF['CLAIM']['ISSUE_DATE'], "nbf" => $CONF['CLAIM']['NOT_BEFORE'], "exp" => $CONF['CLAIM']['EXPIRE'], "data" => array( "id" => $id, "firstname" => $firstname, "lastname" => $lastname, "email" => $email )); http_response_code(200); $jwt = JWT::encode($token, $CONF['CLAIM']['SECRET']); echo json_encode( array( "message" => "Successful login.", "jwt" => $jwt, "email" => $email, "expireAt" => $CONF['CLAIM']['EXPIRE'] )); } else { http_response_code(401); echo json_encode(array("message" => "Login failed")); } } else { http_response_code(401); echo json_encode(array("message" => "Login failed")); } ?>