-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
465 lines (390 loc) · 13.6 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
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
<?php
//db variables
define( 'DB_SERVER', 'localhost' );
define( 'DB_USER', 'root' );
define( 'DB_PW', 'root' );
define( 'DB_NAME', 'swimming' );
//registration variables
$isAccountCreated = null;
$isUsernameAvailable = null;
$ruser_Name = null;
$passwordMatch = null;
$usernameMatch = null;
$isPassMatch = null;
//blowfish
function cryptPass($input, $rounds = 14)
{
$salt = "";
$saltChars = array_merge(range('A','Z'), range('a','z'), range(0,9));
for($i = 0; $i < 22; $i++)
{
$salt .= $saltChars[array_rand($saltChars)];
}
return crypt($input, sprintf('$2y$%02d$', $rounds) . $salt);
}
session_start();
//DB Connection
//change before putting website up
error_reporting( E_ALL );
mysqli_report( MYSQLI_REPORT_STRICT );
try
{
$mysqli = new mysqli( DB_SERVER, DB_USER, DB_PW, DB_NAME );
$connected = true;
}
catch (Exception $e)
{
$connected = false;
}
//Character Set UTF-8
if($connected)
{
if (!$mysqli->set_charset('utf8'))
{
$connected = false;
}
}
//may want to get an email later for security
//may want to validate email and make sure only one is used/unique
//check if user is trying to register
if( isset($_POST[ 'rsubmit' ]) )
{
//check if username and password are entered
if( ( isset( $_POST[ 'ruser_Name' ] ) && !empty($_POST[ 'ruser_Name' ]) ) &&
( isset( $_POST[ 'r_Password' ] ) && !empty($_POST[ 'r_Password' ]) )
)
{
//checks if the first and second passwords match
if( strcmp($_POST[ 'c_Password' ], $_POST[ 'r_Password' ]) === 0)
{
$ruser_Name = $_POST[ 'ruser_Name' ];
$r_Password = $_POST[ 'r_Password' ];
// $remail = $_POST[ 'remail' ];
//sql to check if username is available
$rsql = null;
$rsql = "SELECT Users.Username AS Usernames" .
" FROM Users" .
" WHERE Users.Username = ?";
//Preparing
$rstmt = $mysqli->prepare( $rsql );
//binding parameter
$rstmt->bind_param( "s", $ruser_Name);
//execute
$rstmt->execute();
//bind results
$unresults = null;
$rstmt->bind_result($unresults);
//store results to get properties
$rstmt->store_result();
//variable for username availability
$isUsernameAvailable = $rstmt->num_rows === 0;
//free results
$rstmt->free_result();
//checks if username is available and adds new user to table
if($isUsernameAvailable)
{
$hasedPass = cryptPass($r_Password);
//write sql to create username and password
$isql = null;
$isql = "INSERT INTO users (Username, Password)" .
" VALUES ( ? , ? )";
//preparing
$istmt = $mysqli->prepare( $isql );
//binding parameter
$istmt->bind_param( "ss", $ruser_Name, $hasedPass);
//execute
$istmt->execute();
$istmt->close();
$isAccountCreated = TRUE;
}
}
//The first and second passwords do not match
else
{
$isPassMatch = FALSE;
}
}
}
//checks if user is trying to log in to account
if( isset($_POST[ 'lsubmit' ]) )
{
//checks for both username and password to be entered
if( ( isset( $_POST[ 'user_Name' ] ) && !empty($_POST[ 'user_Name' ]) ) &&
( isset( $_POST[ 'password' ] ) && !empty($_POST[ 'password' ]) ) )
{
$user_Name = $_POST[ 'user_Name' ];
$password = $_POST[ 'password' ];
//gets the hased password that is in the database for this user
//SQL to Prepare
$sql = null;
$sql = 'SELECT Users.Password AS Password' .
' FROM Users' .
' WHERE Users.Username = ?';
//Preparing
$stmt = $mysqli->prepare( $sql );
//binding parameter
$stmt->bind_param( "s", $user_Name) ;
//execute
$stmt->execute();
//bind results
$pwresults = null;
$stmt->bind_result($pwresults);
//store results to get properties
$stmt->store_result();
//checks if anything was returned
if($stmt->num_rows === 1)
{
while($stmt->fetch())
{
//checking password match and if matches then log in
if(crypt($password, $pwresults) === $pwresults)
{
//get UID for later
//SQL to Prepare
$uidsql = null;
$uidsql = 'SELECT Users.UID AS UserID' .
' FROM Users' .
' WHERE Users.Username = ?';
//Preparing
$uidstmt = $mysqli->prepare( $uidsql );
//Binding Parameter
$uidstmt->bind_param("s", $user_Name) ;
//execute
$uidstmt->execute();
//bind results
$uidresults = null;
$uidstmt->bind_result($uidresults);
//store results to get properties
$uidstmt->store_result();
//sets all the variables to the initial settings
//everything is set to null and first page to start in is Teams
while($uidstmt->fetch())
{
$_SESSION[ 'user' ] = $uidresults;
$_SESSION[ 'currentSelection' ] = "Teams";
$_SESSION[ 'teamID' ] = null;
$_SESSION[ 'teamName' ] = "None";
$_SESSION[ 'meetID' ] = null;
$_SESSION[ 'meetName' ] = "None";
$_SESSION[ 'swimmerID' ] = null;
$_SESSION[ 'swimmerName' ] = "None";
$_SESSION[ 'eventID' ] = null;
$_SESSION[ 'eventName' ] = "None";
}
header('Location: search.php');
$passwordMatch = TRUE;
}
//password entered does not match with one in database
else
{
$passwordMatch = FALSE;
}
}
}
//username entered does not exist in database
else
{
$usernameMatch = FALSE;
}
$stmt->free_result();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>Creative - Start Bootstrap Theme</title>
<!-- Bootstrap Core CSS -->
<link rel="stylesheet" href="css/bootstrap.min.css" type="text/css">
<!-- Custom Fonts -->
<link href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Merriweather:400,300,300italic,400italic,700,700italic,900,900italic' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="font-awesome/css/font-awesome.min.css" type="text/css">
<!-- Plugin CSS -->
<link rel="stylesheet" href="css/animate.min.css" type="text/css">
<!-- Custom CSS -->
<link rel="stylesheet" href="css/creative.css" type="text/css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body id="page-top">
<nav id="mainNav" class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand page-scroll" href="#page-top">Home</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li>
<a class="page-scroll" href="#register">Register</a>
</li>
<li>
<a class="page-scroll" href="#about">About</a>
</li>
<li>
<a class="page-scroll" href="#login">LogIn</a>
</li>
<!--
<li>
<a class="page-scroll" href="#contact">Contact</a>
</li>
-->
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container-fluid -->
</nav>
<header>
<div class="header-content">
<div class="header-content-inner">
<h1>KEEP TRACK OF TIMES AND MORE!</h1>
<hr>
<p><strong>Start by creating an account now!</strong></p>
</div>
</div>
</header>
<!-- This section is used to create a new account -->
<section class="bg-primary" id="register">
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 text-center">
<?php
if($isAccountCreated)
{
echo '<h3>Created new Account!</h3>';
echo "<br>";
echo "User Name is: " . $ruser_Name;
echo "<br>";
echo "<br>";
}
else if($isUsernameAvailable === FALSE)
{
echo $ruser_Name . " is already taken please try again.";
}
else if($isPassMatch === FALSE)
{
echo "The passwords do not match please try again.";
}
?>
<h2 class="section-heading">Register</h2>
<form method = "POST" action = "<?php echo htmlentities( $_SERVER['PHP_SELF'] ); ?>">
<div class="form-group">
<label for="userName">User Name</label>
<input type="text" class="form-control" id="newUserName" placeholder="User Name" name= "ruser_Name" maxlength="30">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" id="newPassword" placeholder="Password" name= "r_Password" maxlength="100">
</div>
<div class="form-group">
<label for="confirmPassword">Confirm Password</label>
<input type="password" class="form-control" id="confirmPassword" placeholder="Password" name= "c_Password" maxlength="100">
</div>
<!--
<div class="form-group">
<label for="email"> Email </label>
<input type="email" class="form-control" id="newEmail" placeholder="Email" name= "remail" maxlength="254">
</div>-->
<input type="submit" name="rsubmit" class="btn btn-default" value="Register">
</form>
<hr class="light">
<p class="text-faded">Making an account lets you create teams, view your times, and message your teams.</p>
</div>
</div>
</div>
</section>
<section id="about">
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 text-center">
<h2 class="section-heading">We've got what you need!</h2>
<hr class="light">
<p>Making an account lets you create teams, view your times, and message your teams.</p>
</div>
</div>
</div>
</section>
<!-- This is the section to login -->
<section class="bg-primary" id="login">
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 text-center">
<?php
if($passwordMatch===FALSE)
{
echo '<h3>PASSWORDS DO NOT MATCH TRY AGAIN</h3>';
echo "<br>";
}
else if($usernameMatch===FALSE)
{
echo '<h3> USERNAME DOES NOT EXIST TRY AGAIN </h3>';
echo "<br>";
}
?>
<h2 class="section-heading">Log In</h2>
<form method = "POST" action = "<?php echo htmlentities( $_SERVER['PHP_SELF'] ); ?>" >
<div class="form-group">
<label for="userName">User Name</label>
<input type="text" class="form-control" id="userName" placeholder="User Name" name= "user_Name" maxlength="30">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" id="password" placeholder="Password" name="password" maxlength="100">
</div>
<input type="submit" name="lsubmit" class="btn btn-default" value="LogIn">
</form>
</div>
</div>
</div>
</section>
<!--
<section id="contact">
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 text-center">
<h2 class="section-heading">Let's Get In Touch!</h2>
<hr class="primary">
<p>Questions, problems, or feedback? Give us a call or send us an email and we will get back to you as soon as possible!</p>
</div>
<div class="col-lg-4 col-lg-offset-2 text-center">
<i class="fa fa-phone fa-3x wow bounceIn"></i>
<p>123-456-6789</p>
</div>
<div class="col-lg-4 text-center">
<i class="fa fa-envelope-o fa-3x wow bounceIn" data-wow-delay=".1s"></i>
<p><a href="mailto:[email protected]">[email protected]</a></p>
</div>
</div>
</div>
</section>
-->
<!-- jQuery -->
<script src="js/jquery.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="js/bootstrap.min.js"></script>
<!-- Plugin JavaScript -->
<script src="js/jquery.easing.min.js"></script>
<script src="js/jquery.fittext.js"></script>
<script src="js/wow.min.js"></script>
<!-- Custom Theme JavaScript -->
<script src="js/creative.js"></script>
</body>
</html>