/
LoginScreen.php
81 lines (72 loc) · 2.36 KB
/
LoginScreen.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
session_start();
require_once("dbLogin.php");
require_once("sqlconnector.php");
if (isset($_POST["Login"])) {
$host = "localhost";
$dbuser = "user";
$dbpassword = "user";
$database = "calendapp";
$table = "users";
$connector = new SQLConnector(new Credentials($host, $dbuser, $dbpassword, $database));
$connector->connect();
$warning = "";
$username = trim($_POST["username"]);
$sqlQuery = sprintf("select name, password from %s where name='%s'", $table, $username);
if (!($result = $connector->retrieve($sqlQuery))) {
$warning = "Whoops! Seems like you haven't signed up yet! Click below to sign up! (username not found)";
} else {
if (password_verify($_POST['password'], $result['password'])) {
$warning = "Logged in!";
$_SESSION['loggedIn'] = true; //Stay logged in
$_SESSION['username'] = $username;
$_SESSION['email'] = $connector->retrieve("select email from users where name='$username'")['email'];
header("Location: main.php");
} else {
$warning = "Wrong password!";
}
}
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Login Screen</title>
<link rel="stylesheet" href="Login.css" type="text/css" />
</head>
<body>
<header>
<div class = "container">
<img id = logo src="img/CalendAppLogo.png" alt="CalendApp Logo" /></br>
</header>
</div>
<div class = "form">
<?php
$body = "";
$scriptName = $_SERVER["PHP_SELF"];
$username = "";
$password = "";
echo "<form action='$scriptName' method='post'>
<p>
<input type='text' placeholder='Username' required='required' name='username' value ='$username'/>
<input type='password' placeholder='Password' required='required' name='password' value ='$password'/>
";
if (isset($warning)) { //Print warning
echo "<br />".$warning;
}
echo "</br>
</br>
<input id = 'login' type='submit' name = 'Login' value = 'Login'/>
</br>
</br>
<p>New to CalendApp? Sign Up today!</p>
</form>
<form action='signup.php' method='post'>
<input id= 'sign' type='submit' name='signup' value='Sign Up' />
</form>
</p></br>
";
?>
</div>
</body>
</html>