-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsignup.php
107 lines (91 loc) · 3.46 KB
/
signup.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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Sign up</title>
<SCRIPT TYPE="text/javascript" src="js/sweetalert.min.js"></SCRIPT>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.backstretch.min.js"></script>
</head>
<body>
<style>
.jumbotron{
background-color:rgba(238, 238, 238, 0.56);
margin-top:10%;
}
</style>
<?php
require_once('connectvars.php');
if(isset($_POST['login']))
{
header('Location: index.php');
}
// Connect to the database
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if (isset($_POST['submit'])) {
// Grab the profile data from the POST
$username = mysqli_real_escape_string($dbc, trim($_POST['username']));
$password1 = mysqli_real_escape_string($dbc, trim($_POST['password1']));
$password2 = mysqli_real_escape_string($dbc, trim($_POST['password2']));
if (!empty($username) && !empty($password1) && !empty($password2) && ($password1 == $password2)) {
// Make sure someone isn't already registered using this username
$query = "SELECT * FROM user WHERE username = '$username'";
$data = mysqli_query($dbc, $query);
if (mysqli_num_rows($data) == 0) {
// The username is unique, so insert the data into the database
$query = "INSERT INTO user (username, password) VALUES ('$username', SHA('$password1'))";
mysqli_query($dbc, $query);
// Confirm success with the user
echo '<p>Your new account has been successfully created. You are now ready to log in</a>.</p>';
}
else {
?>
<?php
$username = "";
}
}
else {
echo '<p class="error">You must enter all of the sign-up data, including the desired password twice.</p>';
}
}
mysqli_close($dbc);
?>
<form role="form" method="post" action="">
<fieldset>
<div class="col-md-4 jumbotron col-xs-8 col-xs-offset-2 col-md-offset-4 row">
<div class="row">
<div class="col-md-offset-3 col-md-6 form-group">
<label for="username">Username:</label>
<input type="text" id="username" class="form-control" name="username" value="<?php if (!empty($username)) echo $username; ?>" /><br />
</div>
</div>
<div class="row">
<div class="col-md-offset-3 col-md-6 form-group">
<label for="password1">Password:</label>
<input type="password" id="password1" class="form-control" name="password1" /><br />
</div>
</div>
<div class="row">
<div class="col-md-offset-3 col-md-6 form-group">
<label for="password2">Password (retype):</label>
<input type="password" id="password2" class="form-control" name="password2" /><br />
</div>
</div>
<input class="col-md-offset-3 btn btn-primary" type="submit" class="btn btn-primary" value="Sign Up" name="submit" />
<input class="col-md-offset-3 btn btn-primary" type="submit" value="Log In" name="login" />
</div>
</fieldset>
</form>
</body>
<script type="text/javascript">
$.backstretch([
"t1.jpg",
"t2.jpg",
"t3.jpg"
], {
fade: 2050,
duration: 1000
}); </script>
</html>