-
Notifications
You must be signed in to change notification settings - Fork 0
/
Decode.php
50 lines (44 loc) · 1.34 KB
/
Decode.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: GET, POST");
header("Access-Control-Allow-Headers: *");
$data1 = file_get_contents("php://input");
$data2 = json_decode($data1, true);
$token = $data2['token'];
require 'vendor/autoload.php';
$conn = new mysqli("127.0.0.1", "root", "", "rplayer");
use Firebase\JWT\JWT;
use Firebase\JWT\Key;
$key = "kjhsdkjsbakfjbdkfbsdjhbfjsd";
try
{
$values = JWT::decode($token, new Key($key, 'HS256'));
$data = (array)$values;
$values2 = (array)$data['data'];
$email = $values2['email'];
$password = $values2['password'];
$query = "SELECT * FROM credentials WHERE email = '$email'";
$result = mysqli_query($conn, $query);
if(mysqli_num_rows($result) > 0)
{
$row = mysqli_fetch_row($result);
if(password_verify($password, $row[1]))
{
echo json_encode("Authorized");
}
else
{
echo json_encode("Unauthorized");
}
exit();
}
else
{
echo json_encode("Unauthorized");
}
}
catch(Exception $e)
{
echo json_encode("Unauthorized");
}
?>