-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
168 lines (151 loc) · 4.44 KB
/
login.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php include "../inc/dbinfo.inc"; ?>
<html>
<head>
<meta charset="UTF-8">
<title>Login | Tasks Tracker</title>
<style>
body {
background-color: #F2F2F2;
}
h1 {
font-size: 40px;
font-weight: bold;
text-align: center;
margin-top: 50px;
}
form {
background-color: white;
border: 2px solid #F2F2F2;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
margin: 50px auto;
padding: 20px;
width: 400px;
}
table {
margin-top: 20px;
margin-bottom: 20px;
width: 100%;
border-collapse: collapse;
}
td {
padding: 10px;
text-align: right;
vertical-align: middle;
border-bottom: 1px solid #ddd;
}
input[type="text"], input[type="password"] {
border: 1px solid #CCCCCC;
border-radius: 5px;
font-size: 16px;
height: 30px;
padding: 5px;
width: 100%;
}
button[type="submit"] {
background-color: #3e8e41;
border: none;
border-radius: 5px;
color: white;
cursor: pointer;
font-size: 16px;
height: 40px;
margin-top: 10px;
width: 100%;
}
input[type="submit"]:hover {
background-color: #3e8e41;
}
.button-group {
display: flex;
justify-content: space-between;
margin-top: 20px;
}
tr:hover {background-color: #f5f5f5;}
button {
background-color: #4CAF50;
color: white;
border: none;
cursor: pointer;
padding: 10px;
border-radius: 5px;
margin-right: 5px;
}
button:hover {
background-color: #3e8e41;
}
</style>
</head>
<body>
<h1 id="welcome">Welcome to Tasks Manager</h1>
<form action="<?php echo $_SERVER['SCRIPT_NAME'] ?>" method="POST">
<table>
<tr>
<td><label for="username">Username:</label></td>
<td><input type="text" id="username" name="username" maxlength="45" size="30" required/></td>
</tr>
<tr>
<td><label for="password">Password:</label></td>
<td><input type="password" id="password" name="password" maxlength="45" size="30" required/></td>
</tr>
</table>
<button type="submit" name="loginBtn" class="button">Login</button>
</form>
<form action="<?php echo $_SERVER['SCRIPT_NAME'] ?>" method="POST">
<div class="button-group">
<button type="submit" name="createBtn" class="button">Sign Up</button>
<button type="submit" name="forgotBtn" class="button">Forgot Password</button>
</div>
</form>
<!-- Js function here (Not use. For Example Purpose -->
<script>
function createUser(){
window.location.replace("https://ec2-54-82-112-252.compute-1.amazonaws.com/createUser.php");
}
function forgotPass(){
window.location.replace("https://ec2-54-82-112-252.compute-1.amazonaws.com/forgotPassword.php");
}
</script>
<?php
/* Connect to MySQL and select the database. */
$connection = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD);
if (mysqli_connect_errno()) echo "Failed to connect to MySQL: " . mysqli_connect_error();
$database = mysqli_select_db($connection, DB_DATABASE);
$username = htmlentities($_POST['username']);
$password = htmlentities($_POST['password']);
if (!strlen($username)) $username = "a";
if (isset($_POST['createBtn'])) header("Location: createUser.php");
if (isset($_POST['forgotBtn'])) header("Location: forgotPassword.php");
if (strlen($username) && strlen($password)){
if( checkPass($connection,$username,$password) && isset($_POST['loginBtn'])) {
setcookie('username', $username, time() + (86400 * 7), "/");
// header("Location: index.php");
header("Location: http://ec2-54-82-112-252.compute-1.amazonaws.com/user/$username");
} else {
// echo "<div style='text-align: center;'>Password is not correct! Please try again.</div>";
echo "<script>alert('Password is incorrect! Please try again!');</script>";
}
}
?>
<!-- Clean up. -->
<?php
mysqli_free_result($result);
mysqli_close($connection);
?>
</body>
</html>
<?php
function checkPass($connection, $username, $password) {
$u = mysqli_real_escape_string($connection, $username);
$p = mysqli_real_escape_string($connection, $password);
// echo "inside checkPass";
$query = "SELECT password,full_name FROM user_details WHERE username='$u';";
$result = mysqli_query($connection, $query);
$query_data = mysqli_fetch_row($result);
if(strcmp($query_data[0],$password)===0) {
setcookie('fullname', $query_data[1], time() + (86400 * 7), "/");
return true;
} else {
return false;
}
}
?>