-
Notifications
You must be signed in to change notification settings - Fork 2
/
signup.php
173 lines (146 loc) · 6.07 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
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
<?php
include 'connection.php';
include 'function.php';
session_start();
if (isset($_SESSION['loginuser'])) {
session_destroy();
echo "<script>location.href='signup.php'</script>";
}
?>
<!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">
<title>Signup Page</title>
<link href="css/signupstyle.css" rel='stylesheet' type='text/css'>
<!-- Custom Fonts -->
<link href="https://fonts.googleapis.com/css?family=Nunito:300,400,700" rel="stylesheet" type="text/css">
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<style type="text/css">
.navbar-brand{
font-size: 1.8em;
}
.error{
color: red;
}
</style>
</head>
<body>
<div class="navbar-default navbar-fixed-top">
<div class = "container">
<div class ="navbar-header">
<button class ="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="homepage.php">SpringBoard</a>
</div>
<div class="collapse navbar-collapse">
<ul class ="nav navbar-nav">
<li class="active"><a href="homepage.php">Home</a></li>
<li><a href="explore.php">Explore</a></li>
<li><a href ="fundrequest.php">Start a project</a></li>
</ul>
</div>
</div>
</div>
<?php
$signName = $passCode = $confirmCode = "";
$signNameErr = $passCodeErr = $confirmCodeErr = "";
//if (isset($_POST['signup'])) {
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
//validate username, only consists of characters and numbers, 5-32
if (empty($_POST['signName'])) {
$signNameErr = "Name is required";
} else {
$signName = test_input($_POST['signName']);
if (strlen($_POST['signName']) < 6 || strlen($_POST['signName']) > 32) {
$signNameErr = "Your Username must contain 6 to 32 characters!";
} elseif (preg_match("/\s+/", $signName)) {
$signNameErr = "Username can't contain space.";
} elseif (!preg_match("/^[A-Za-z][A-Za-z0-9]/", $signName)) {
$signNameErr = "Username should starting with a letter.";
}
}
//validate password
if (empty($_POST['passCode'])) {
$passCodeErr = "Password is required";
}
elseif (($_POST['passCode'] == $_POST['confirmCode'])) {
$passCode = test_input($_POST['passCode']);
$confirmCode = test_input($_POST['confirmCode']);
if (strlen($_POST['passCode']) < 6 || strlen($_POST['passCode']) > 16) {
$passCodeErr = "Password must contain 6 to 16 characters!";
} elseif (preg_match("/[^A-Za-z0-9_]/", $passCode)) {
$passCodeErr = "Password contains special characters.";
} elseif (!preg_match("/[0-9]+/",$passCode)) {
$passCodeErr = "Password Must Contain At Least 1 Number!";
} elseif (!preg_match("/[A-Z]+/",$passCode)) {
$passCodeErr = "Password Must Contain At Least 1 Uppercase Letter!";
} elseif (!preg_match("/[a-z]+/",$passCode)) {
$passCodeErr = "Password Must Contain At Least 1 Lowercase Letter!";
}
} else {
$passCodeErr = "Please Check You've Entered Or Confirmed Your Password!";
}
//check occupied
if ($signNameErr == "" && $passCodeErr == "") {
$stmt = $conn->prepare("SELECT UID FROM Accounts WHERE UID = ?");
$stmt->bind_param("s", $signName);
$stmt->execute();
$checkExist = $stmt->get_result();
if($checkExist->num_rows > 0) {
$signNameErr = "This Name has been occupied! Please try another.";
} else {
//insert into database;
$hashed_passcode = password_hash($passCode, PASSWORD_BCRYPT);
$insertAcc = $conn->prepare("INSERT INTO Accounts(UID, Passcode) VALUES (?,?)");
$insertAcc->bind_param("ss", $signName, $hashed_passcode);
$insertAcc->execute();
$insertUserProf = $conn->prepare("INSERT INTO UserProfiles(UID) VALUES ('$signName')");
$insertUserProf->execute();
//redirect to homepage as logged in.
$_SESSION['loginuser'] = $signName;
echo "<script>location.href='homepage.php'</script>";
}
}
}
?>
<div class="main">
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
<div class="lable">
Username:<br/>
<input type="text" name="signName" value="<?php echo $signName; ?>">
<span class="error"><br/><?php echo $signNameErr;?></span><br/>
</div>
<div class="lable-2">
Password:<br/>
<input type="password" name="passCode">
<span class="error"><br/><?php echo $passCodeErr;?></span><br/>
Confirm Your Password:<br/>
<input type="password" name="confirmCode">
</div>
<h2 style="color: red;">By creating an account, you agree to our Terms & Conditions</h2>
<div class="submit">
<input type="submit" name="signup" value="Sign Up">
</div>
<div class="clear"> </div>
</form>
</div><!--end-main-->
<div class="copy-right">
<p><a href="homepage.php"> Back To Homepage </a></p>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="js/bootstrap.min.js"></script>
<script type="application/x-javascript">
addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false);
function hideURLbar(){ window.scrollTo(0,1); }
</script>
</body>
</html>