-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSignup.php
More file actions
173 lines (164 loc) · 6.76 KB
/
Signup.php
File metadata and controls
173 lines (164 loc) · 6.76 KB
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
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
//Load Composer's autoloader
require '../vendor/autoload.php';
if(!isset($_SERVER['HTTP_REFERER'])){
header("Location: ./Login.php");
exit;
}
session_start();
if(isset($_SESSION['username']) =="") {
setcookie(session_name(), '', 100);
session_unset();
session_destroy();
header("Location: ./Login.php");
}
if(isset($_POST['logout'])){
setcookie(session_name(), '', 100);
session_unset();
session_destroy();
header("Location: ./Login.php");
}
$showAlert=false;
$showError=false;
$exists=false;
if($_SERVER["REQUEST_METHOD"]=="POST"){
include "dbconnect.php";
$username=$_POST["username"];
$password=$_POST["password"];
$cpassword=$_POST["cpassword"];
$email=$_POST["email"];
$sql="SELECT * FROM `login` where `Email`='$email'";
$res=mysqli_query($conn,$sql);
$num=mysqli_num_rows($res);
if($num==0){
//validate password atleast 6 characters
if(strlen($password)<6){
$showError="Password must be atleast 6 characters";
}
else{
if(($password == $cpassword) && $exists==false){
$hash=password_hash($password,PASSWORD_DEFAULT);
$token = bin2hex(random_bytes(20)); // Generate a random token
$sql="INSERT INTO `login` (`Email`,`username`, `password`, `login_lD`, `token`) VALUES ('$email','$username', '$password', NULL, '$token');";
$result = mysqli_query($conn, $sql);
if ($result) {
// Send the token to the user's email
$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'lifelinkiiita@gmail.com'; // Your gmail address
$mail->Password = 'nmqejgxnjkcssrqz'; // Your gmail password or app password
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('lifelinkiiita@gmail.com', 'LifeLink'); // Set your name and email address
$mail->addAddress($email); // Recipient's email address
$mail->isHTML(true);
$mail->Subject = 'Verification Token';
$mail->Body = "Use this token to verify your account: $token";
if(!$mail->send()) {
$showError = 'Unable to send verification email.';
} else {
$showAlert = true;
}
}
}
else {
$showError = "Passwords do not match";
}
}
}
if($num>0){
$exists="Either username not available or you already have an account";
}
}
?>
<!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.0">
<title>Signup</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="stylesheet" href="index.css">
</head>
<body>
<header>
<nav class="bg-black text-white p-2 flex justify-between items-center sticky">
<div class="ml-4 flex items-center">
<img src="./images/logo.png" alt="">
<h1 class="text-3xl ml-2 font-semibold">LifeLink</h1>
</div>
<ul class="flex justify-evenly mr-8">
<li class="text-lg font-semibold px-4"><a href="./Userpage.php">Home</a></li>
<li class="text-lg font-semibold px-4">
<form action="./Login.php" method="post">
<input type="submit" name="logout" value="Logout">
</form>
</li>
</ul>
</nav>
</header>
<main class="flex">
<div class=" w-1/2 flex justify-center items-center h-screen">
<div class="flex flex-col justify-center items-center">
<img src="./images/signup.jpg" alt="">
</div>
</div>
<div class=" w-1/2 flex justify-center items-center h-screen">
<div class="flex flex-col justify-center items-center">
<h1 class="font-semibold text-3xl">Enter the details of the new admin</h1>
<form action="./Signup.php" method="post">
<div class="flex flex-col justify-center items-center">
<input type="text" id="username" name="username" placeholder="Username" class="border-2 border-black rounded-lg p-2 mt-4" required>
<input type="email" id="email" name="email" placeholder="Email ID" class="border-2 border-black rounded-lg p-2 mt-4" required>
<input type="password" id="password" name="password" placeholder="Password" class="border-2 border-black rounded-lg p-2 mt-4" required>
<input type="password" id="cpassword" name="cpassword" placeholder="Confirm Password" class="border-2 border-black rounded-lg p-2 mt-4" required>
<button class="bg-red-500 text-white px-4 py-2 rounded-lg mt-2">SignUp</button>
</div>
</form>
<?php
if($showAlert) {
$message = "Token Sent To Mail";
echo "<script type='text/javascript'>alert('$message');</script>";
}
if($showError){
?>
<div class="text-red-500 font-semibold text-xl text-center">
<?php echo $showError; ?>
</div>
<?php
}
if($exists){
?>
<div class="text-red-500 font-semibold text-xl text-center">
Account already exists or username not available!!
</div>
<?php
}
?>
</div>
</div>
</main>
<!-- footer -->
<footer class="flex items-center justify-center h-24 bg-black text-white">
<div class="container mx-auto flex items-center">
<span class="mr-2">
<img src="images/logo.png" alt="Footer Icon" class="h-10 w-10">
</span>
<span class="text-lg">© 2023 LifeLink. All rights reserved.</span>
</div>
<div class="ml-4">
<span>
<a href="https://github.com/RayLikesAnime/LifeLink">
<img src="images/github.png" alt="Another Icon" class="h-16 w-16 mx-20">
</a>
</span>
</div>
</footer>
</body>
</html>