Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Lucksi
GitHub Repository: Lucksi/Mr.Holmes
Path: blob/master/GUI/Actions/Credentials_Controller.php
1071 views
1
<?php
2
/*ORIGINAL CREATOR: Luca Garofalo (Lucksi)
3
AUTHOR: Luca Garofalo (Lucksi)
4
Copyright (C) 2021-2023 Lucksi <[email protected]>
5
License: GNU General Public License v3.0*/
6
7
$Input_username = $_POST["username"];
8
$Input_Password = $_POST["password"];
9
10
function Confront_Creds(){
11
global $Input_username;
12
global $Input_Password;
13
$Flag = 0;
14
$Login_file = "../Credentials/Users.json";
15
$Reader = file_get_contents($Login_file);
16
$Parser = json_decode($Reader,true);
17
foreach($Parser["Users"] as $Data){
18
if($Input_username == $Data["Username"] and $Input_Password == $Data["Password"]){
19
$Flag = 1;
20
}
21
}
22
if ($Flag == 1){
23
$Session_File = "../Session/Token.txt";
24
header("Location: ../Database/Main.php");
25
$Creator = fopen($Session_File,"w")or die("SESSION-ERROR");
26
fwrite($Creator,"LOG FOR YOUR CURRENT SESSION_THIS WILL EXPIRE ONCE YOU QUIT YOUR SESSION");
27
fclose($Creator);
28
}
29
else {
30
header("Location: ../Login/Login.php");
31
echo "
32
<script>
33
alert('USERNAME OR PASSWORD INCORRECT');
34
</script>";
35
}
36
}
37
38
function Check_Creds(){
39
global $Input_username;
40
global $Input_Password;
41
if ($Input_Password == "" and $Input_username == ""){
42
header("Location: ../Login/Login.php");
43
echo "
44
<script>
45
alert('USERNAME OR PASSWORD NOT INSERTED');
46
</script>
47
";
48
}
49
else{
50
Confront_Creds();
51
}
52
}
53
54
function Create_User(){
55
global $Input_username;
56
global $Input_Password;
57
$Flag = 0;
58
$Database = "../Credentials/Users.json";
59
if(file_exists($Database)){
60
$Reader = file_get_contents($Database);
61
$Parser = json_decode($Reader,true);
62
$Credentials = $Parser["Users"];
63
if ($Input_Password == "" and $Input_username == ""){
64
echo "
65
<script>
66
alert('USERNAME OR PASSWORD NOT INSERTED');
67
</script>
68
";
69
}
70
else {
71
foreach($Parser["Users"] as $Data){
72
if($Input_username == $Data["Username"]){
73
$Flag = 1;
74
}
75
}
76
if ($Flag == 1){
77
echo "<script>
78
alert('OPS USER $Input_username ALREADY EXIST');
79
</script>";
80
}
81
else {
82
echo "<script>
83
alert('USER $Input_username CREATED');
84
</script>";
85
$json_string = file_get_contents($Database);
86
$json = json_decode($json_string, true);
87
array_push($json["Users"], array("Username" => "$Input_username", "Password" => "$Input_Password"));
88
$strNew = json_encode($json,JSON_PRETTY_PRINT);
89
file_put_contents($Database, $strNew);
90
}
91
}
92
}
93
else {
94
echo "<script>alert('ESSENTIAL FILE NOT FOUND EXIT')</script>";
95
exit(0);
96
}
97
}
98
if(isset($_POST["Button2"])){
99
Create_User();
100
}
101
elseif(isset($_POST["Button"])){
102
Check_Creds();
103
}
104
?>
105