commit a9853c39cc2a4397404f86e93e15d687f884addb Author: Archie Fox Date: Sat Jun 8 14:22:07 2024 +0300 Init commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/classes/MyDB.php b/classes/MyDB.php new file mode 100644 index 0000000..fcf2d8a --- /dev/null +++ b/classes/MyDB.php @@ -0,0 +1,17 @@ +open('mysqlitedb.db'); + } +} + +$db = new MyDB(); + +$db->exec('CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT UNIQUE, pass TEXT)'); \ No newline at end of file diff --git a/index.php b/index.php new file mode 100644 index 0000000..dfb56ed --- /dev/null +++ b/index.php @@ -0,0 +1,45 @@ +query("SELECT * FROM users WHERE name = '$name'"); + $auth = $result->fetchArray(); + + if ($auth['name'] !== $name || password_verify($pass, $auth['pass']) !== true) { + $res = 'Login or password is wrong!'; + } + session_start(); + $_SESSION['name'] = $auth['name']; + $_SESSION['id'] = $auth['id']; + header("Location: secret.php"); + exit(); +} +?> + + + + +
+

Authorization

+
+

+

+

+

+
+

Registration

+
+ + \ No newline at end of file diff --git a/mysqlitedb.db b/mysqlitedb.db new file mode 100644 index 0000000..212831b Binary files /dev/null and b/mysqlitedb.db differ diff --git a/registration.php b/registration.php new file mode 100644 index 0000000..b960821 --- /dev/null +++ b/registration.php @@ -0,0 +1,43 @@ +query("SELECT * FROM users WHERE name = '$name'"); + $arr = $result->fetchArray(); + if ($arr !== false) { + $res = "This name is already used!"; + } else { + $db->exec("INSERT INTO users (name, pass) VALUES ('$name', '$pass')"); + header("Location: index.php"); + } +} + +?> + + + +
+

Registration

+
+

+

+

+

+
+

Authorization

+
+ + diff --git a/secret.php b/secret.php new file mode 100644 index 0000000..37abeef --- /dev/null +++ b/secret.php @@ -0,0 +1,28 @@ +"; +echo 'Your Name: ' . $_SESSION['name'] . "
"; + +if ($_GET['do'] === 'logout') { + session_destroy(); + header("Location: index.php"); + exit(); +} + +?> + + + +
+ Logout +
+ + \ No newline at end of file diff --git a/style.css b/style.css new file mode 100644 index 0000000..f98f15d --- /dev/null +++ b/style.css @@ -0,0 +1,58 @@ +* { + margin: 0; + padding: 0; + box-sizing: border-box; +} + +body { + background-color: #454444; + color: white; +} + +.auth { + display: flex; + flex-direction: column; + align-items: center; + margin-top: 20%; + margin-left: auto; + margin-right: auto; + width: 250px; + padding: 30px; + border: white solid 1px; + border-radius: 10px; +} + +.auth h1 { + font-size: 22px; +} + +input { + padding: 5px; + margin: 5px; + border-radius: 5px; +} + +input[type=button], input[type=submit], input[type=reset] { + background-color: #04AA6D; + border: none; + color: white; + padding: 8px 16px; + text-decoration: none; + margin: 4px 2px; + cursor: pointer; +} + +form { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; +} + +.auth a { + color: white; +} + +.error { + color: red; +} \ No newline at end of file diff --git a/templates/footer.php b/templates/footer.php new file mode 100644 index 0000000..308b1d0 --- /dev/null +++ b/templates/footer.php @@ -0,0 +1,2 @@ + + diff --git a/templates/header.php b/templates/header.php new file mode 100644 index 0000000..1d80996 --- /dev/null +++ b/templates/header.php @@ -0,0 +1,8 @@ + + + + + + + <?= $title; ?> +