-
Notifications
You must be signed in to change notification settings - Fork 0
/
sign_up.php
177 lines (148 loc) · 5.02 KB
/
sign_up.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
<?php
//Perform registration
//Connect to database
require_once('db_core.php');
Global $MYSQL_CODE_DUPLICATE_KEY;
//Perform form validation
if(isset($_POST['firstname_text']) &&
isset($_POST['lastname_text']) &&
isset($_POST['username_text']) &&
isset($_POST['password_text']) &&
isset($_POST['email_text'])
)
{
$fn = $_POST['firstname_text'];
$ln = $_POST['lastname_text'];
$un = $_POST['username_text'];
$pw = $_POST['password_text'];
$et = $_POST['email_text'];
if(!(empty($fn) ||
empty($ln) ||
empty($un) ||
empty($pw) ||
empty($et)))
{
//Print either error or success;
$result = validateDetails($un,$pw,$et);
if($result=="success")
{
$reg_res = registerUser($fn,$ln,$un,$pw,$et);
if(strcmp($reg_res,$MYSQL_CODE_DUPLICATE_KEY)==0)
{
echo "A user already exists with that username";
}
else if($reg_res==true)
{
CreateProfile($un,$fn);
echo "Sucessfully registered. Redirecting you...<br><br>";
header("refresh:4;url=index");
}
else
{
echo "Something went wrong, please try again later";
}
}
else
{
echo $result;
}
}
else
{
echo "Enter details and then submit you idiot!";
}
}
CreateProfile("rvnd",'Rvnd');
function CreateProfile($un,$fn)
{
$content = "<?php require_once('profile.php')".'?'.'>';
Write($un.'.php',$content);
}
function registerUser($fn,$ln,$un,$pw,$et)
{
$result = Fetch("insert into users values(NULL,'$un','$pw','$fn','$ln','$et',NULL)");
return $result;
}
function un_validate($user)
{
//Username can contain alphabets, numbers, underscores, full stops and must start with an alphabet only
$re = "/^[A-Za-z][\w\-\.]*$/i";
return preg_match($re,$user);
}
function email_validate($em)
{
$re = "/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i";
return preg_match($re,$em);
}
function validateDetails($un,$pw,$et)
{
//Validating password length
if(strlen($pw)<6)
return "Password too short";
//Validating username
if(!un_validate($un))
return "Invalid username";
//Validating email
if(!email_validate($et))
return "Invalid email";
return "success";
}
?>
<script type="application/javascript">
function performSignUp() {
var un_text = $('#username_text').val();
var pw_text = $('#password_text').val();
if (un_text != "" || pw_text != "") {
$('#login_form_element').submit();
} else {
alert("Please enter your credentials");
}
}
</script>
<link rel="stylesheet" href="elements.css" />
<form action="" method="post" id="login_form_element" target="_self">
<div id="form_box" align="center">
<h5>Register</h5>
<hr>
<div class="input_label container">
<div class="row">
<div class="col-12">
<span class="custom_label">First Name</span><input class="input_box" type="text" name="firstname_text" />
</div>
</div><br>
<div class="row">
<div class="col-12">
<span class="custom_label">Last Name</span><input class="input_box" type="text" name="lastname_text" />
</div>
</div><br>
<div class="row">
<div class="col-12">
<span class="custom_label">Username</span><input class="input_box" type="text" name="username_text" />
</div>
</div><br>
<div class="row">
<div class="col-12">
<span class="custom_label">Password</span><input class="input_box" name="password_text" type="password" />
</label>
</div>
</div><br>
<div class="row">
<div class="col-12">
<span class="custom_label">Email</span><input class="input_box" name="email_text" type="text" />
</label>
</div>
</div><br>
<div class="row">
<div class="col-12">
<span class="custom_button" name="login_button" onmouseup="performSignUp();">Sign Up</span>
</div>
</div><br><br>
<div class="row">
<div class="col-6" align="left">
<a href="index.php" target="_self">
<span class="custom_button">Login</span></a>
</div>
</div>
</div>
</div>
</form>