servnest/inc/all.inc.php
2021-05-14 21:10:56 +02:00

54 lines
1.3 KiB
PHP

<?php
if (strpos($_SERVER['PHP_SELF'], "inc.php") !== false)
exit("This file is meant to be included.");
function addNiverLog($message, $outputLines) {
$logs = "\n" . date("Y-m-d H:i:s") . " " . $message . "\n";
foreach ($outputLines as $outputLine) {
$logs = $logs . " " . $outputLine . "\n";
}
file_put_contents(ROOT_PATH . "/niver.log", $logs, FILE_APPEND);
}
function checkAction($action) {
if ($action === "delete")
return "un";
else if ($action === "add")
return "";
else
exit("ERROR: wrong value for action");
}
function checkPassword($username, $password) {
$username2[0] = $username;
$db = new PDO('sqlite:' . DB_PATH);
$op = $db->prepare('SELECT username, password FROM users WHERE username = ?');
$op->execute($username2);
$dbPassword = $op->fetch()['password'];
return password_verify($password, $dbPassword);
}
function userExist($username) {
$usernameArray[0] = $username;
$db = new PDO('sqlite:' . DB_PATH);
$op = $db->prepare('SELECT username FROM users WHERE username = ?');
$op->execute($usernameArray);
$data = $op->fetch();
if (isset($data['username']))
$dbUsername = $data['username'];
else
$dbUsername = NULL;
if (isset($dbUsername)) {
return true;
} else {
return false;
}
}