-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignup.php
213 lines (178 loc) · 8.55 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
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
<!-- Sign Up Page -->
<?php
$alertMessage = "";
// If Submit Button is clicked:
if(isset($_POST['SubmitButton'])){
// Fetching the user-entered values for the following fields
$name = $_POST['validationName'];
$username = $_POST['validationUsername'];
$password = $_POST['validationPassword'];
$email = $_POST['validationEmail'];
$country = $_POST['validationCountry'];
// Establishing a connection with the MySQL Database
$conn = new mysqli('localhost', 'root', '', 'project_rti_portal');
// If there is any error, print connection failed
if($conn->connect_error){
echo "$conn->connect_error";
die("Connection Failed : ".$conn->connect_error);
}
else{
// Username Validation
$query = mysqli_query($conn, "SELECT * FROM users WHERE username='".$username."'");
$count = mysqli_num_rows($query);
// If username already exists, then raise an alert-message
if($count!=0) {
$alertMessage = "Username already exists..! Please enter another username";
}
else{
// Password validation : Checking for atleast one number, atleast one Capital Letter, small letter and special character
if(!preg_match("#[0-9]+#", $password)) {
$alertMessage = "Password must contain atleast one number!";
}
elseif(!preg_match("#[A-Z]+#", $password)) {
$alertMessage = "Password must contain atleast one Capital Letter!";
}
elseif(!preg_match("#[a-z]+#", $password)) {
$alertMessage = "Password must contain atleast one Small Letter";
}
elseif(!preg_match("'/[\'^£$%&*()}{@#~?><>,|=_+¬-]/'", $password)) {
$alertMessage = "Password must contain atleast one special character";
}
// Correct Credentials : If all the above conditions are satisfied, then add new entry in database
else{
$statement = $conn->prepare("Insert into users(name, username, password, email, country) Values(?, ?, ?, ?, ?)");
$statement->bind_param("sssss", $name, $username, $password, $email, $country);
$execval = $statement->execute();
// Close the connection
$statement->close();
$conn->close();
// Redirect to login page
header("Location: login.php");
}
}
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sign Up - RTI Portal</title>
<link rel="icon" href="https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fwww.wvba.com%2Fimages%2FInfo-I-Logo.png&f=1&nofb=1" type="image/png" width="30" height="25">
<!-- External CSS File -->
<link type="stylesheet" href="signup.css">
<!-- Javascript File -->
<script src="SignUp.js" type="text/javascript"></script>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-F3w7mX95PdgyTmZZMECAngseQB83DfGTowi0iMjiWaeVhAn4FJkqJByhZMI3AhiU" crossorigin="anonymous">
<!-- Font Awesome Icon-->
<script src="https://kit.fontawesome.com/03801c7b15.js" crossorigin="anonymous"></script>
</head>
<body>
<form class="container col-lg-5 col-md-8 col-sm-11 mt-4" style="background-color: #D4F2D2;" method="post">
<div class="h1 py-4 text-center">Sign Up</div>
<!-- Name -->
<div class="row row-cols-2 my-3">
<div class="col-3 d-flex flex-row-reverse">
<label for="validationName" class="col-form-label">Name: </label>
</div>
<div class="col-6">
<input type="text" class="form-control" id="validationName" name="validationName" required
oninvalid="setCustomValidity(\'Please enter alphabets only\'\)">
</div>
</div>
<!-- User ID -->
<div class="row row-cols-2 mb-3">
<div class="col-3 d-flex flex-row-reverse">
<label for="validationUsername" class="col-form-label">Username: </label>
</div>
<div class="col-4">
<input type="text" id="validationUsername" name="validationUsername" class="form-control placeicon notranslate" aria-describedby="usernameHelpInline" minlength="5" maxlength="12" placeholder="" required>
</div>
<div class="col-auto">
<span id="usernameHelpInline" class="form-text"><i class="fas fa-info-circle pe-2"></i>Must be 5-12 characters long</span>
</div>
</div>
<!-- Password -->
<div class="row row-cols-2 my-3">
<div class="col-3 d-flex flex-row-reverse">
<label for="validationPassword" class="col-form-label">Password: </label>
</div>
<div class="col-4">
<input type="password" id="validationPassword" name="validationPassword" class="form-control placeicon notranslate" aria-describedby="passwordHelpInline" minlength="7" maxlength="12" placeholder="" required />
<div><input class="col-2" type="checkbox" onclick="myFunction()">Show Password</div>
</div>
<div class="col-auto">
<span id="passwordHelpInline" class="form-text"><i class="fas fa-info-circle pe-2"></i>Must be 7-12 characters long</span>
</div>
</div>
<!-- Email ID -->
<div class="row row-cols-2 my-3">
<div class="col-3 d-flex flex-row-reverse">
<label for="validationEmail" class="col-form-label">Email: </label>
</div>
<div class="col-6">
<i class="glyphicon glyphicon-user"></i>
<input type="email" class="form-control placeicon" id="validationEmail" name="validationEmail"> <!--placeholder="" -->
</div>
</div>
<!-- Country -->
<div class="row row-cols-2 my-3">
<div class="col-3 d-flex flex-row-reverse">
<label for="validationCountry" class="col-form-label">Country: </label>
</div>
<div class="col-auto">
<select class="form-select" id="validationCountry" name="validationCountry" required>
<option selected disabled value="">(Please select a country)</option>
<option>India</option>
<option>Russia</option>
<option>United States of America</option>
<option>United Kingdom</option>
</select>
</div>
</div>
<!-- Language -->
<div class="row row-cols-2 my-3">
<div class="col-3 d-flex flex-row-reverse">
<label for="validationLanguage" class="form-label">Language: </label>
</div>
<div class="col-auto">
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" name="validationLanguage" id="inlineCheckbox1" value="English" required>
<label class="form-check-label" for="inlineCheckbox1">English</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="checkbox" name="validationLanguage" id="inlineCheckbox2" value="Non-English" required>
<label class="form-check-label" for="inlineCheckbox2">Hindi</label>
</div>
</div>
</div>
<div class="col-12 text-center">
<p class="text-danger fw-bold"> <?php echo $alertMessage?></p>
<button class="btn btn-primary mb-2" type="submit" name="SubmitButton" onclick="required(CheckPassword())">Submit</button>
<p class="text-muted pb-4">Already have an account? <a href="login.php">Login</a></p>
</div>
</form>
<div class="container col-lg-4 col-md-8 col-sm-12 footer p-3 mb-4">
<div class="text-center s1">
<h1 >RTI Portal</h1>
<p>now you can challenge corruption</p>
</div>
</div>
<!-- Scripts for JQuery, Popper and Bootstrap -->
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/[email protected]/dist/umd/popper.min.js"
integrity="sha384-W8fXfP3gkOKtndU4JGtKDvXbO53Wy8SZCQHczT5FMiiqmQfUpWbYdTil/SxwZgAN" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"
integrity="sha384-skAcpIdS7UcVUC05LJ9Dxay8AXcDYfBJqt1CJ85S/CFujBsIzCIv+l9liuYLaMQ/" crossorigin="anonymous"></script>
<!-- Google Translate API -->
<script type="text/javascript">// <![CDATA[
function googleTranslateElementInit() {
new google.translate.TranslateElement({pageLanguage: 'en' , includedLanguages : 'en,hi,ta,gu,bn,mr'}, 'google_translate_element');
}
// ]]></script>
<script src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit" type="text/javascript"></script>
</body>
</html>