Skip to content

Instantly share code, notes, and snippets.

@vncloudsco

vncloudsco/sg.php

Created Jul 3, 2020
Embed
What would you like to do?
session_start();
if (isset($_POST["signal"]) && isset($_POST["signal"]) == 1) {
$strPass = shell_exec("sudo cat /usr/src/lifesafety");
$strPass = mb_substr(trim($strPass), 0, 8);
$mysqli = new mysqli("localhost", "cpanel_user", $strPass, "c_panel");
if (!$mysqli) {
exit(json_encode(array("status" => 0, "msg" => "Connection to database is lost.")));
}
$username = isset($_POST["username"]) && $_POST["username"] ? $_POST["username"] : "";
$password = isset($_POST["password"]) && $_POST["password"] ? $_POST["password"] : "";
$saveme = isset($_POST["saveme"]) && $_POST["saveme"] ? $_POST["saveme"] : "";
if ($username == "" || $password == "") {
exit(json_encode(array("status" => 0, "msg" => "Data is not enough.")));
}
if (!($result = $mysqli->query("SELECT * FROM accounts WHERE username='" . $username . "'"))) {
exit(json_encode(array("status" => 0, "msg" => "An error occured when retrieving data.")));
}
$numb = $result->num_rows;
if ($numb != 1) {
exit(json_encode(array("status" => 0, "msg" => "Username or password is incorrect.")));
}
$row = $result->fetch_array(MYSQLI_ASSOC);
$existingHashFromDb = $row["password"];
$isPasswordCorrect = password_verify($password, $existingHashFromDb);
if (!$isPasswordCorrect) {
exit(json_encode(array("status" => 0, "msg" => "Username or password is incorrect.")));
}
$_SESSION["user"] = $row;
if ($saveme) {
setcookie("user", json_encode($row), time() + 3600
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.