This repository was archived by the owner on Jan 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.php
More file actions
183 lines (155 loc) · 6.76 KB
/
server.php
File metadata and controls
183 lines (155 loc) · 6.76 KB
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
<?php
session_start();
// variable declaration
$oldusername = "";
$username = "";
$oldpassword = "";
$email = "";
$errors = array();
$_SESSION['success'] = "";
$address_1 = "";
$address_2 = "";
$city = "";
$state = "";
$zipfive = "";
// connect to database
$db = mysqli_connect('127.0.0.1', 'root', '', 'registration');
// REGISTER USER
if (isset($_POST['reg_user'])) {
// receive all input values from the form
$username = mysqli_real_escape_string($db, $_POST['username']);
$email = mysqli_real_escape_string($db, $_POST['email']);
$password_1 = mysqli_real_escape_string($db, $_POST['password_1']);
$password_2 = mysqli_real_escape_string($db, $_POST['password_2']);
$address_1 = mysqli_real_escape_string($db, $_POST['address_1']);
$address_2 = mysqli_real_escape_string($db, $_POST['address_2']);
$city = mysqli_real_escape_string($db, $_POST['city']);
$state = mysqli_real_escape_string($db, $_POST['state']);
$zipfive = mysqli_real_escape_string($db, $_POST['zipfive']);
// form validation: ensure that the form is correctly filled
// validate(Address_1, Address_2, City, State, ZipFive)
if (empty($username)) { array_push($errors, "Username is required"); }
if (empty($email)) { array_push($errors, "Email is required"); }
if (empty($password_1)) { array_push($errors, "Password is required"); }
if (empty($password_2)) { array_push($errors, "Please confirm password"); }
if (empty($address_1)) { array_push($errors, "Address 1 is required"); }
if (empty($city)) { array_push($errors, "City is required"); }
if (empty($state)) { array_push($errors, "State is required"); }
if (empty($zipfive)) { array_push($errors, "Zipcode is required"); }
if ($password_1 != $password_2) {
array_push($errors, "The two passwords do not match");
}
$validate = shell_exec("python VerificationAPI.py $address_1 $address_2 $city $state $zipfive");
if ($validate[0] == "F"){
array_push($errors, "Please enter a valid address");
}
// register user if there are no errors in the form
if (count($errors) == 0) {
$password = md5($password_1);//encrypt the password before saving in the database
$query = "INSERT INTO users (username, email, password, address_1, address_2, city, state, zipfive)
VALUES('$username', '$email', '$password', '$address_1', '$address_2', '$city', '$state', '$zipfive')";
mysqli_query($db, $query);
$_SESSION['username'] = $username;
$_SESSION['success'] = "You are now logged in";
header('location: index.php');
}
}
// ...
// LOGIN USER
if (isset($_POST['login_user'])) {
$username = mysqli_real_escape_string($db, $_POST['username']);
$password = mysqli_real_escape_string($db, $_POST['password']);
if (empty($username)) {
array_push($errors, "Username is required");
}
if (empty($password)) {
array_push($errors, "Password is required");
}
if (count($errors) == 0) {
$password = md5($password);
$query = "SELECT * FROM users WHERE username='$username' AND password='$password'";
$results = mysqli_query($db, $query);
if (mysqli_num_rows($results) == 1) {
$_SESSION['username'] = $username;
$_SESSION['success'] = "You are now logged in";
header('location: index.php');
}else {
array_push($errors, "Wrong username/password combination");
}
}
}
// CHANGING ACCOUNT INFORMATION
if (isset($_POST['acc_changed'])) {
// receive all input values from the form
$oldusername = mysqli_real_escape_string($db, $_POST['oldusername']);
$username = mysqli_real_escape_string($db, $_POST['username']);
$email = mysqli_real_escape_string($db, $_POST['email']);
$password_1 = mysqli_real_escape_string($db, $_POST['password_1']);
$oldpassword = mysqli_real_escape_string($db, $_POST['oldpassword']);
$address_1 = mysqli_real_escape_string($db, $_POST['address_1']);
$city = mysqli_real_escape_string($db, $_POST['city']);
$state = mysqli_real_escape_string($db, $_POST['state']);
$zipfive = mysqli_real_escape_string($db, $_POST['zipfive']);
// form validation: ensure that the form is correctly filled
// validate(Address_1, Address_2, City, State, ZipFive)
if (empty($oldusername)) { array_push($errors, "Old Username is required"); }
// if (empty($email)) { array_push($errors, "Email is required"); }
// if (empty($password_1)) { array_push($errors, "Password is required"); }
// if (empty($password_2)) { array_push($errors, "Please confirm password"); }
// if (empty($address_1)) { array_push($errors, "Address 1 is required"); }
// if (empty($city)) { array_push($errors, "City is required"); }
// if (empty($state)) { array_push($errors, "State is required"); }
// if (empty($zipfive)) { array_push($errors, "Zipcode is required"); }
// if ($password_1 != $password_2) {
// array_push($errors, "The two passwords do not match");
// }
$validate = shell_exec("python VerificationAPI.py $address_1 $address_2 $city $state $zipfive");
if ($validate[0] == "F"){
array_push($errors, "Please enter a valid address");
}
$query = "SELECT * FROM users WHERE username='$oldusername'";
$results = mysqli_query($db, $query);
if (mysqli_num_rows($results) == 0) {
array_push($errors, "Account does not Exist");
}
// register user if there are no errors in the form
if (count($errors) == 0) {
// $password = md5($password_1);//encrypt the password before saving in the database
if (!empty($password)){
$password = md5($password_1);//encrypt the password before
$query = "UPDATE users SET password = '$password' WHERE username = '$oldusername'";
mysqli_query($db,$query);
}
if (!empty($email)){
$query = "UPDATE users SET email = '$email' WHERE username = '$oldusername'";
mysqli_query($db,$query);
}
if (!empty($address_1)){
$query = "UPDATE users SET address_1 = '$address_1' WHERE username = '$oldusername'";
mysqli_query($db,$query);
}
if (!empty($city)){
$query = "UPDATE users SET city = '$city' WHERE username = '$oldusername'";
mysqli_query($db,$query);
}
if (!empty($state)){
$query = "UPDATE users SET state = '$state' WHERE username = '$oldusername'";
mysqli_query($db,$query);
}
if (!empty($zipfive)){
$query = "UPDATE users SET zipfive = '$zipfive' WHERE username = '$oldusername'";
mysqli_query($db,$query);
}
if (!empty($username)){
$query = "UPDATE users SET username = '$username' WHERE username = '$oldusername'";
mysqli_query($db,$query);
}
// $query = "INSERT INTO users (username, email, password, address_1, address_2, city, state, zipfive)
// VALUES('$username', '$email', '$password', '$address_1', '$address_2', '$city', '$state', '$zipfive')";
// mysqli_query($db, $query);
// $_SESSION['username'] = $username;
// $_SESSION['success'] = "You are now logged in";
header('location: index.php');
}
}
?>