-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.php
118 lines (91 loc) · 4.01 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
<!--main page doc for login or options-->
<?php session_start(); ?>
<?php include "config.php"; ?>
<?php include "header.php"; ?>
<?php
//set message variable to blank
$message = "";
//if submit button is clicked
if(isset($_POST['submit'])){
// Define $username and $password
$username = $_POST['username'];
$password = $_POST['password'];
// To protect MySQL injection for Security purpose
$username = mysqli_real_escape_string($connect, $username);
$password = mysqli_real_escape_string($connect, $password);
//Query to find if username and password info matches
$query = "SELECT * FROM user WHERE username ='$username'";
$select_user_query = mysqli_query($connect, $query);
if (!$select_user_query) {
die("Query failed : " . mysqli_error($connect));
}else {
//gather data from the database for that username
while($row = mysqli_fetch_array($select_user_query)){
$db_user_id = $row['user_id'];
$db_username = $row['username'];
$db_password = $row['password'];
$db_user_firstname = $row['firstname'];
$db_user_lastname = $row['lastname'];
}
//password verify is a function used to match a password to a hash
if (password_verify($_POST["password"], $db_password)) {
$_SESSION['username'] = $db_username;
$_SESSION['first_name'] = $db_user_firstname;
$_SESSION['last_name'] = $db_user_lastname;
$_SESSION['user_id'] = $db_user_id;
header("Location: pages/dashboard.php");
} else{
$message= "That password is incorrect." ;
}
}}
?>
<!--form for login input info or other options-->
<body>
<div class="jumbotron jumbotron-fluid text-center margin-b-0">
<p class="text-center"><img src="img/Armitage_logo.jpg" width="150" alt="Armitage logo" /></p>
<h3>Armitage Accounting Login</h3>
<hr class="my-4">
<form id='login-form' action="index.php" method="post">
<div class="row justify-content-center">
<div class="col-lg-4 col-md-6 col-sm-9">
<?php
echo $message;
?>
<input name="username" type="text" id="username" placeholder=" username" autocomplete="on" class="form-control" size="30"><br>
<input name="password" pattern=".{10,}" type="password" id="password" placeholder=" password" class="form-control" size="30"><br>
<!--allow user to choose company-->
<?php
$companyID_query = "SELECT company_id, company_name FROM company ORDER BY company_name ASC";
$companyID_result = mysqli_query($connect, $companyID_query);
?>Select a Company to access: <br>
<select name="company">
<?php
while ($row = mysqli_fetch_array($companyID_result)){
echo "<option value".$row[0].">",$row[1].$row[2].$row[3]."</option>";
}
?>
</select><br>
<br>
<!--
****
PLEASE CHANGE
THE API KEY at "data-sitekey="
****
****
-->
<button class="btn btn-warning btn-lg " class="g-recaptcha" data-sitekey="AIzaSyDtjVkmvSw6czRVoY_eZVQj9TKjx6IfqlQ" data-callback='onSubmit' name="submit" type="submit">Login</button>
<br>
<br><a class="btn btn-secondary btn-sm" href="forgotPassword.php?forgot=<?php echo uniqid(true);?>" role="button">Forgot Password</a>
<a class="btn btn-secondary btn-sm" href="registerForm.php" role="button">New User</a></div>
</div>
</form>
</div>
</body>
<!--invisible recatcha is initiated-->
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<script>
function onSubmit(token) {
document.getElementById("login-form").submit();
}
</script>
<?php include "pages/footer.php"; ?>