This repository has been archived by the owner on Mar 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
validate_token.php
45 lines (40 loc) · 1.53 KB
/
validate_token.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
<?php
// Use JWT TOken
// include "koneksi.php";
$connect = file_get_contents(".env");
$dbjson = json_decode($connect);
$koneksi = mysqli_connect($dbjson->host, $dbjson->username, $dbjson->password, $dbjson->db);
include_once 'vendor/firebase/php-jwt/src/BeforeValidException.php';
include_once 'vendor/firebase/php-jwt/src/ExpiredException.php';
include_once 'vendor/firebase/php-jwt/src/SignatureInvalidException.php';
include_once 'vendor/firebase/php-jwt/src/JWT.php';
use \Firebase\JWT\JWT;
// end Jwt token
$jwt = isset($_POST['token']) ? $_POST['token'] : "";
if($jwt){
try{
$key = "bakekok";
$decoded = JWT::decode($jwt, $key, array('HS256'));
http_response_code(200);
$dataUser = $decoded->data->username;
$dataPass = $decoded->data->password;
$query = mysqli_query($koneksi, "SELECT * FROM admin a where a.username = '$dataUser' and a.password = '$dataPass' ");
$cek = mysqli_num_rows($query);
if($cek < 0){
$fail = array("success"=>false, "message"=>"Akses ditolak");
exit($fail);
}
// echo json_encode(array(
// "message" => "Access dibolehkan",
// "data" => $decoded->data
// ));
}catch(Exception $e){
header('Content-Type: application/json');
$fail = array("success"=>false, "error"=>$e->getMessage(), "message"=>"Akses ditolak");
exit(json_encode($fail));
}
}else{
$fail = array("success"=>false, "message"=>"Akses ditolak");
exit(json_encode($fail));
}
?>