-
Notifications
You must be signed in to change notification settings - Fork 1
/
AuthKey.php
49 lines (40 loc) · 1.33 KB
/
AuthKey.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
<?php
include_once("config.php"); //import config file.
$onecode = $_POST["onecode"].$_salt;
$onecode = hash("sha256", $onecode);
$returnJSON = array();
$jsonFile = json_decode(file_get_contents("OneCode.json"));
$codeHash = $jsonFile -> ONECODE;
$codeUsed = $jsonFile -> USED;
$codeTime = $jsonFile -> TIME;
$codeErrorTime = $jsonFile -> ERRORTIME;
$interval = floor((strtotime(date("Y-m-d H:i:s",intval(time())))-strtotime($codeTime))%86400/60); //Calculate the time interval.
if($interval <= 5){
//Check the time.
if($codeErrorTime < 3){
//Check the password times.
if(($onecode == $codeHash) && ($codeUsed == false) ){
//Check the password.
$returnJSON['CODE'] = 200;
$returnJSON['Message'] = "OK";
$jsonFile -> USED = TRUE;
file_put_contents('OneCode.json', json_encode($jsonFile));
echo json_encode($returnJSON);
}else{
$returnJSON['CODE'] = 501;
$returnJSON['Message'] = "Authorization Error!";
$jsonFile -> ERRORTIME++;
file_put_contents('OneCode.json', json_encode($jsonFile));
echo json_encode($returnJSON);
}
}else{
$returnJSON['CODE'] = 502;
$returnJSON['Message'] = "The Key is Not Available.";
echo json_encode($returnJSON);
}
}else{
$returnJSON['CODE'] = 503;
$returnJSON['Message'] = "Overtime!";
echo json_encode($returnJSON);
}
?>