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