-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
146 lines (135 loc) · 4.7 KB
/
index.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
<?php
session_start();
if(isset($_SESSION["logged_in"])) {
if($_SESSION["logged_in"]) {
header("location:dashboard.php");
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Science Market - Home | Where people discuss and collaborate with experts</title>
<meta name="description" content="Science Market is an online market place to connect with peers, people, groups or expert. Discuss topics in question answer forum, connect with experts under expert connect, collaborate with people and provide favours." >
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="styles/header.css">
<link rel="stylesheet" type="text/css" href="/styles/login.css" >
<link rel="stylesheet" type="text/css" href="styles/footer.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="js/login.js"></script>
<link rel="stylesheet" href="styles/bootstrap.min.css">
<script src="js/bootstrap.min.js"></script>
<link href="https://fonts.googleapis.com/css?family=Ubuntu" rel="stylesheet">
</head>
<body>
<?php
include "connectDb.php";
$message="<div class='msg-default'>Login Portal</div>";
$pwddb="";
$userid="";
$nameError="*";
$nameSuc="";
$pwdError="*";
$checked=$success=true;
if ($_SERVER["REQUEST_METHOD"] == "POST") {
#check for empty field
if(empty($_POST["userid"])) {
$message="<div class='alert alert-danger login-message'>Enter mandatory fields</div>";
$checked=false;
}
else {
#check for empty field.
$userid=processData($_POST["userid"]);
if(empty($_POST["pwd"])) {
$message="<div class='alert alert-danger login-message'>Enter mandatory fields</div>";
$checked=false;
}
else {
$pwd=processData($_POST["pwd"]);
}
}
if($checked==true) {
try {
$sql="select status,encrypt_pwd from users where user_id='".$userid."'";
$stmt=$conn->prepare($sql);
$stmt->execute();
if($stmt->rowCount() > 0) {
$row=$stmt->fetch();
$pwddb=$row['encrypt_pwd'];
$status=$row['status'];
#check is user entered the correct password.
if(md5($pwd)!=$pwddb) {
$message="<div class='alert alert-danger login-message'>Invalid credentials</div>";
$success=false;
}
else {
if(strtoupper($status) != 'A') {
$message = "<div class='alert alert-warning login-message'>Account is de-activated</div>";
$success=false;
}
#Redirect to dashboard welcome page for correct credentials.
else {
include "session.php"; #start user session
header("location:dashboard.php");
}
}
}
else {
$message="<div class='alert alert-warning login-message'>Looks like you are a new user. Please register</div>";
}
}
catch(PDOException $e) {
$message= "<div class='alert alert-danger login-message'>Internal server error</div>";
}
}
}
#Function to trim extra spaces/backslashes and avoiding cross-scripting
function processData($text) {
$text=trim($text);
$text=stripslashes($text);
$text=htmlspecialchars($text);
return $text;
}
?>
<div id="bg-window"></div>
<!--<div class="container"> -->
<div id="main-container">
</br>
<div id="login-logo">
<img id="" src="img/logo4.svg" width="70" height="70"/>
<img id="" src="img/logo.svg" width="250" height="70"/>
</div></br>
<?php echo $message; ?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<div class="form-group form-section">
<label for="name-area" class="form-labels">Username</label>
<input class="form-control input-class" id="name-area" type="text" name="userid" placeholder="Enter login ID" value="<?php echo $userid;?>" />
</div>
<div class="form-group form-section">
<label for="pwd-area" class="form-labels">Password</label>
<input class="form-control input-class" id="pwd-area" type="password" name="pwd" placeholder="Enter password" />
</div>
<!-- <div class="g-signin2" data-onsuccess="onSignIn"></div></br> -->
<div class="form-row-2">
<table>
<tr><td>
<span class="checkbox">
<label><input class="" type="checkbox" value="" name="remMe">Remember me</label>
</span>
</td>
<td>
<a id="fp-link" href="frgt_pwd.php" target="_blank" name="fgtPwd">Forgot Password?</a>
</td>
</tr>
</table>
</div></br>
<div class="form-row-3">
<input class="btn btn-primary inp-button" type="submit" value="Sign in" />
<a href="register.php" class="btn btn-primary inp-button">New user? Sign up</a>
</div>
</form>
</div>
<!--</div>-->
</body>
</html>