From a8beb03f69571ec952c5ba59a0cf4a6e6946a496 Mon Sep 17 00:00:00 2001 From: Luka Hietala Date: Thu, 6 Nov 2025 10:36:25 +0200 Subject: [PATCH] perus autentikaatio ja tietokanta --- admin.php | 25 ++++++++++++++++++++ database.php | 18 +++++++++++++++ index.php | 8 +++++-- login.php | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++ logout.php | 8 +++++++ 5 files changed, 122 insertions(+), 2 deletions(-) create mode 100644 admin.php create mode 100644 database.php create mode 100644 login.php create mode 100644 logout.php diff --git a/admin.php b/admin.php new file mode 100644 index 0000000..de68c36 --- /dev/null +++ b/admin.php @@ -0,0 +1,25 @@ + + + + + + + + Opettaja näkymä + + + + + Kirjaudu ulos + + + \ 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 @@ -0,0 +1,18 @@ +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 @@ -1,3 +1,7 @@ \ No newline at end of file +require_once "database.php" +?> + + + Kirjaudu sisään + \ 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 @@ -0,0 +1,65 @@ +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(); + } +} +?> + + + + + + Kirjaudu + + +

Kirjaudu opettajana

+
+
+ + + + + + + + + +
+ + + +
+ + + +
+
+ +
+ + diff --git a/logout.php b/logout.php new file mode 100644 index 0000000..be5d201 --- /dev/null +++ b/logout.php @@ -0,0 +1,8 @@ + \ No newline at end of file -- 2.47.3