forked from khanhdnk/akathon01-23
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauthentication.php
47 lines (41 loc) · 1.53 KB
/
authentication.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
<?php
session_start();
require_once("./functions/functions.php");
$url = "https://b81155ba-05ce-415b-9ca4-b83d935e46a6-asia-south1.apps.astra.datastax.com/api/rest/v2/keyspaces/test/users/rows";
$token = "AstraCS:PXhWiFwCPFWfmLXqOGtkOlCU:ef2043b13fcc33dd3e63368eabf3a4379cf561fda6dec8ae2490832acde2ab39";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"Accept: application/json",
"X-Cassandra-Token: $token"
));
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response);
if (isset($_POST["username"]) && isset($_POST["password"])) {
$username = sanitise_input($_POST["username"]);
$password = sanitise_input($_POST["password"]);
}
?>
<?php
foreach ($data->data as $row) {
if (($password == $row->password) && ($username == $row->username && ($row->admin == "true"))) {
header('Location: admin.php');
$_SESSION['admin'] = true;
$_SESSION['userid'] = $row->id;
$_SESSION['row'] = $row;
exit();
} else if (($password == $row->password) && ($username == $row->username)) {
header('Location: dashboard.php');
$_SESSION['authenticated'] = true;
$_SESSION['userid'] = $row->id;
$_SESSION['row'] = $row;
exit();
}else{
$errorlogin = urlencode("Username or password is incorrect!");
header("Location: login.php?errorlog=$errorlogin");
}
}
?>