diff --git a/admin.php b/admin.php
new file mode 100644
index 0000000..de68c36
--- /dev/null
+++ b/admin.php
+<?php
+require_once "database.php";
+
+// estä pääsy muilta paitsi opettajilta
+if (!isset($_SESSION['user_id'])) {
+ echo "Sinulla ei ole riittäviä oikeuksia";
+ die();
+}
+
+?>
+
+<!DOCTYPE html>
+<html lang="fi">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>Opettaja näkymä</title>
+</head>
+<body>
+ <?php echo $_SESSION['user_name']; ?>
+ <a href="logout.php">
+ Kirjaudu ulos
+ </a>
+</body>
+</html>
\ No newline at end of file
diff --git a/database.php b/database.php
new file mode 100644
index 0000000..17f5e65
--- /dev/null
+++ b/database.php
+<?php
+// aloittaa session ja luo yhteyden tietokantaan
+if (session_status() === PHP_SESSION_NONE) {
+ session_start();
+}
+
+$servername = "localhost";
+$username = "root";
+$password = "";
+$database = "taitaja2025";
+
+$conn = new mysqli($servername, $username, $password, $database);
+$conn->set_charset("utf8mb4");
+
+if ($conn->connect_error) {
+ die("failed to connect: " . $conn->connect_error);
+}
+?>
\ No newline at end of file
diff --git a/index.php b/index.php
index 353e2b1..e8e957b 100644
--- a/index.php
+++ b/index.php
<?php
- echo "Taitaja 2025"
-?>
\ No newline at end of file
+require_once "database.php"
+?>
+
+<a href="login.php">
+ Kirjaudu sisään
+</a>
\ No newline at end of file
diff --git a/login.php b/login.php
new file mode 100644
index 0000000..57ea947
--- /dev/null
+++ b/login.php
+<?php
+require_once 'database.php';
+
+// kirjautuminen
+if ($_SERVER['REQUEST_METHOD'] == 'POST') {
+ // ota tiedot formista
+ $name = mysqli_real_escape_string($conn, trim($_POST['name'] ?? ''));
+ $password = mysqli_real_escape_string( $conn, trim($_POST['password'] ?? ''));
+
+ if (!empty($name) && !empty($password)) {
+ // etsi käyttäjä
+ $sql = "SELECT id, name, password FROM users WHERE name = '{$name}'";
+ $result = $conn->query($sql);
+
+ if ($result->num_rows > 0) {
+ $user = $result->fetch_assoc();
+
+ // tarkista salasanan hash, php defaultti (bcrypt)
+ if (password_verify($password, $user['password'])) {
+ $_SESSION['user_id'] = $user['id'];
+ $_SESSION['user_name'] = $user['name'];
+ header('Location: admin.php');
+ exit();
+ }
+ }
+
+ // katkaise yhteys tietokantaan
+ $conn->close();
+ }
+}
+?>
+
+<html lang="fi">
+<head>
+ <meta charset="UTF-8">
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <title>Kirjaudu</title>
+</head>
+<body>
+ <h1>Kirjaudu opettajana</h1>
+ <form method="POST" action="">
+ <fieldset>
+ <table>
+ <tr>
+ <td>
+ <label for="name">Nimi:</label>
+ </td>
+ <td>
+ <input type="text" name="name" required>
+ </td>
+ </tr>
+ <tr>
+ <td>
+ <label for="password">Salasana:</label>
+ </td>
+ <td>
+ <input type="password" name="password" required>
+ </td>
+ </tr>
+ </table>
+ </fieldset>
+ <button type="submit">Kirjaudu</button>
+ </form>
+</body>
+</html>
diff --git a/logout.php b/logout.php
new file mode 100644
index 0000000..be5d201
--- /dev/null
+++ b/logout.php
+<?php
+// tuhoaa session, mikä "kirjauduttaa" käyttäjän ulos
+require_once 'database.php';
+
+session_destroy();
+header('Location: index.php');
+exit();
+?>
\ No newline at end of file