From 99d6e1948700bee867f5625f5d33d4e9e56d27e5 Mon Sep 17 00:00:00 2001 From: JelmerHinssen Date: Wed, 8 Mar 2017 16:45:26 +0100 Subject: [PATCH] Password verification --- src/Application/Login.php | 18 +++++++++++++++--- templates/login.phtml | 5 ++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/Application/Login.php b/src/Application/Login.php index 0de24c5..b353f10 100644 --- a/src/Application/Login.php +++ b/src/Application/Login.php @@ -24,11 +24,23 @@ class Login { }); $app->post('/login', function ($request, $response, $args) { // Render index view + $post = $request->getParsedBody(); - if(isset($_POST["username"])){ - echo "Jouw naam is: " . $_POST["username"] . " en je wachtwoord is: " . $_POST["password"] . "
\n"; + $user = $this->db->gebruikers("username = ?", $post["username"]); + if ($user->count("*") === 0){ + echo "Onjuiste gebruikersnaam of wachtwoord"; + } else { + if(password_verify($post["password"], $user["password"])){ + session_start(); + $_SESSION["user"] = [ + "uuid" => $user["uuid"], + "username" => $user["username"] + ]; + }else{ + echo "fout"; + } } - $newResponse = $response->withHeader('Location', 'index.php'); + $newResponse = $response->withHeader('Location', ''); return $this->renderer->render($newResponse, 'login.phtml', $args); }); } diff --git a/templates/login.phtml b/templates/login.phtml index 595a861..7394117 100644 --- a/templates/login.phtml +++ b/templates/login.phtml @@ -29,6 +29,9 @@ body{ color: #ff6000; } + .footer{ + text-align: center; + }
@@ -48,7 +51,7 @@