-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.php
163 lines (154 loc) · 6.54 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
<?php
require_once("Includes/DB.php");
require_once("Includes/Functions.php");
require_once("Includes/sessions.php")
?>
<?php
if (isset($_POST['Submit']))
{
$userName = $_POST['userName'];
$pwd = $_POST['Password'];
$confpwd = $_POST['PasswordConfirm'];
date_default_timezone_set("Asia/Kolkata");
$currtime = time();
$dateTime = strftime("%Y-%m-%d %H:%M:%S", $currtime);
if (empty($userName)||empty($pwd)||empty($confpwd)) {
$_SESSION["ErrorMessage"] = "All Fields must be filled out";
Redirect_to("index.php");
} else if (strlen($userName) < 3) {
$_SESSION["ErrorMessage"] = "Username should be greater then 2 characters";
Redirect_to("index.php");
} else if (strlen($userName) > 50) {
$_SESSION["ErrorMessage"] = "Username should be less then 50 characters";
Redirect_to("index.php");
} else if ($pwd !== $confpwd) {
$_SESSION["ErrorMessage"] = "Password doesn't match";
Redirect_to("index.php");
} else if (checkUserNameExist($userName, 'users')) {
$_SESSION["ErrorMessage"] = "Username already exist";
Redirect_to("index.php");
}
else {
global $connectingDB;
$hashedPwd = password_hash($pwd, PASSWORD_DEFAULT);
$sql = "INSERT INTO users(datetime, username, password)";
$sql .= "VALUES(:dateTime,:userName,:password)"; // dummy variable to prevent sql injection
$stmt = $connectingDB->prepare($sql);
$stmt->bindValue(':dateTime',$dateTime);
$stmt->bindValue(':userName',$userName);
$stmt->bindValue(':password',$hashedPwd);
$execute=$stmt->execute();
if ($execute) {
$_SESSION["SuccessMessage"] = "User added Successfully";
Redirect_to("blog.php");
} else {
$_SESSION["ErrorMessage"] = "Something Went Wrong!!";
Redirect_to("index.php");
}
}
}
?>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="">
<title></title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<link rel="stylesheet" href="CSS/style.css">
<script src="https://kit.fontawesome.com/d5a041e6b5.js" crossorigin="anonymous"></script>
</head>
<body>
<!-- Navbar -->
<div style="height:10px; background-color: #27aae1;"></div>
<nav class="navbar navbar-expand-lg bg-dark navbar-dark">
<div class="container">
<a href="#" class="navbar-brand">CMS Blog</a>
<ul class="navbar-nav ml-auto">
<li class="nav-item">
<a href="login.php" class="nav-link text-warning">
<i class="fas fa-user"></i>Admin Login</a>
</li>
</ul>
</div>
</div>
</nav>
<div style="height:10px; background-color: #27aae1;"></div>
<!-- End of Navbar -->
<!-- Header -->
<header class="bg-dark text-white py-3">
<div class="container">
<div class="row">
<div class="col-md-12">
<h1><i class="fas fa-text-height" style="color: #27aae1"></i>Welcome To CMS</h1>
</div>
</div>
</div>
</header>
<!--End of Header-->
<section class="container py-2 mb-4">
<div class="row justify-content-center">
<div class="offset-lg-1 col-lg-10 align-items-center" style="min-height: 360px;">
<?php echo ErrorMessage();
echo SuccessMessage();
?>
<form class="" action="index.php" method="post">
<div class="card bg-secondary text-light mb-3">
<div class="card-header">
<h1>Register Here</h1>
</div>
<div class="card-body bg-dark">
<div class="form-group">
<label for="title"><span class="fieldInfo">Username: </span></label>
<input class="form-control" type="text" id="title" name="userName" placeholder="Type Username Here" value="">
</div>
<div class="form-group">
<label for="Password"><span class="fieldInfo">Password: </span></label>
<input class="form-control" type="password" id="Password" name="Password" placeholder="Type Password Here" value="">
</div>
<div class="form-group">
<label for="confirm"><span class="fieldInfo">Confirm Password: </span></label>
<input class="form-control" type="password" id="confirm" name="PasswordConfirm" placeholder="Rewrite Password Here" value="">
</div>
<div class="row">
<div class="col-lg-6 mb-2">
<a href="index.php" class="btn btn-warning btn-block"><i class="fas fa-arrow-left"></i>Cancel</a>
</div>
<div class="col-lg-6 mb-2">
<button type="submit" name="Submit" class="btn btn-success btn-block">
<i class="fas fa-check">Register</i>
</button>
</div>
</div>
<br>
<div class="row">
<div class="col-12 text-center">
<h5 class="lead"> <a href="userLogin.php">Already Have an Account?Login Here!</a> </h5>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</section>
<!-- Footer -->
<div class="bg-dark text-white">
<div class="container">
<div class="row">
<div class="col">
<p class="lead text-center small">The Content-Management-Blog By Shreeansh Gupta and Sangam Prasad in <span id="year"></span></p>
</div>
</div>
</div>
</div>
<div style="height:10px; background-color: #27aae1;"></div>
<!-- EndFooter -->
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<<script type="text/javascript">
$('#year').text(new Date().getFullYear());
</script>
</body>
</html>