From f1fcba3e83dfd4c15515e895203bc62b52cc1553 Mon Sep 17 00:00:00 2001 From: William Miceli Date: Mon, 25 Nov 2019 04:31:19 -0500 Subject: [PATCH] User authentication setup - first test --- var/www/login.php | 28 ++++++++++++++++++++++++++++ var/www/loginCheck.php | 39 +++++++++++++++++++++++++++++++++++++++ var/www/logout.php | 27 +++++++++++++++++++++++++++ var/www/phptest.php | 12 ++++++++++-- 4 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 var/www/login.php create mode 100644 var/www/loginCheck.php create mode 100644 var/www/logout.php diff --git a/var/www/login.php b/var/www/login.php new file mode 100644 index 0000000..82554d2 --- /dev/null +++ b/var/www/login.php @@ -0,0 +1,28 @@ + + + + + + FriendBook Login + + + + +
+

Please Login

+
+ User: +
+ Password: +
+ +
+ + diff --git a/var/www/loginCheck.php b/var/www/loginCheck.php new file mode 100644 index 0000000..f479258 --- /dev/null +++ b/var/www/loginCheck.php @@ -0,0 +1,39 @@ +setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + echo "Connected successfully"; + if(count($_POST) > 0){ + $matchingUsers = $connection->query("SELECT COUNT(*) FROM login WHERE username = '".$_POST["Username"]."' and pword = '".$_POST["Password"]."'"); + if($matchingUsers > 0){ + // User has been authenticated; set user as logged in + $_SESSION["loggedInUser"] = "".$_POST["Username"].""; + $_SESSION["loginError"] = ""; + // Move onto landing page + header("Location: /landingPage.html"); + die(); + }else{ + // No matching users found, send user error + $_SESSION["loginError"] = "Invalid Username or Password"; + // Return to login page + header("Location: /login.php"); + die(); + } + }else{ + // Return to login page, as credentials were not captured + $_SESSION["loginError"] = "Login credentials not found, please try again"; + header("Location: /login.php"); + die(); + } +} +catch(PDOException $e){ + echo "Error: " . $e->getMessage(); +} +?> \ No newline at end of file diff --git a/var/www/logout.php b/var/www/logout.php new file mode 100644 index 0000000..3b7c9d9 --- /dev/null +++ b/var/www/logout.php @@ -0,0 +1,27 @@ + + + + + + FriendBook Logout + + + + + + + +

You have been successfully logged out.

+ + + diff --git a/var/www/phptest.php b/var/www/phptest.php index 9ffb6a9..4ba50ac 100644 --- a/var/www/phptest.php +++ b/var/www/phptest.php @@ -1,4 +1,6 @@ -

PHP Test Page - Connecting to MySQL

+

PHP Test Page

+ +

Connecting to MySQL

+

PHP Session Info

+ \ No newline at end of file