aboutsummaryrefslogtreecommitdiff
path: root/user
diff options
context:
space:
mode:
Diffstat (limited to 'user')
-rw-r--r--user/login.php23
-rw-r--r--user/logout.php13
2 files changed, 36 insertions, 0 deletions
diff --git a/user/login.php b/user/login.php
new file mode 100644
index 0000000..7c892e8
--- /dev/null
+++ b/user/login.php
@@ -0,0 +1,23 @@
+<?php
+require '../config.php';
+require_once(TEMPLATES_PATH . "/header.php");
+session_start();
+
+$conn = new PDO($config['db']['dsn'], $config['db']['username'], $config['db']['password']);
+
+// Performing SQL query
+$query = "SELECT id, username, password FROM users WHERE username = '$_POST[username]'";
+$result = $conn->query($query)->fetch();
+
+if(password_verify($_POST['password'], $result['password'])) {
+ echo 'password verified';
+ $_SESSION['user_name'] = $result['username'];
+ $_SESSION['user_id'] = $result['id'];
+} else {
+ echo 'wrong password';
+}
+
+header("Refresh: 2; URL=$_SERVER[HTTP_REFERER]");
+
+require_once(TEMPLATES_PATH . "/footer.php");
+?>
diff --git a/user/logout.php b/user/logout.php
new file mode 100644
index 0000000..26bbfa0
--- /dev/null
+++ b/user/logout.php
@@ -0,0 +1,13 @@
+<?php
+require '../config.php';
+require_once(TEMPLATES_PATH . "/header.php");
+
+session_start();
+unset($_SESSION['user_name']);
+unset($_SESSION['user_id']);
+
+echo 'Session cleared';
+header("Refresh: 2; URL=$_SERVER[HTTP_REFERER]");
+
+require_once(TEMPLATES_PATH . "/footer.php");
+?>