/
signup.php
148 lines (100 loc) · 4.03 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Register</title>
<link rel="stylesheet" href="css/style1.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
<div class="container">
<div class="form-box box">
<header>Sign Up</header>
<hr>
<form action="#" method="POST">
<div class="form-box">
<?php
session_start();
include "connection.php";
if (isset($_POST['register'])) {
$name = $_POST['username'];
$email = $_POST['email'];
$pass = $_POST['password'];
$cpass = $_POST['cpass'];
$check = "select * from users where email='{$email}'";
$res = mysqli_query($conn, $check);
$passwd = password_hash($pass, PASSWORD_DEFAULT);
$key = bin2hex(random_bytes(12));
if (mysqli_num_rows($res) > 0) {
echo "<div class='message'>
<p>This email is used, Try another One Please!</p>
</div><br>";
echo "<a href='javascript:self.history.back()'><button class='btn'>Go Back</button></a>";
} else {
if ($pass === $cpass) {
$sql = "insert into users(username,email,password) values('$name','$email','$passwd')";
$result = mysqli_query($conn, $sql);
if ($result) {
echo "<div class='message'>
<p>You are register successfully!</p>
</div><br>";
echo "<a href='login.php'><button class='btn'>Login Now</button></a>";
} else {
echo "<div class='message'>
<p>This email is used, Try another One Please!</p>
</div><br>";
echo "<a href='javascript:self.history.back()'><button class='btn'>Go Back</button></a>";
}
} else {
echo "<div class='message'>
<p>Password does not match.</p>
</div><br>";
echo "<a href='signup.php'><button class='btn'>Go Back</button></a>";
}
}
} else {
?>
<div class="input-container">
<i class="fa fa-user icon"></i>
<input class="input-field" type="text" placeholder="Username" name="username" required>
</div>
<div class="input-container">
<i class="fa fa-envelope icon"></i>
<input class="input-field" type="email" placeholder="Email Address" name="email" required>
</div>
<div class="input-container">
<i class="fa fa-lock icon"></i>
<input class="input-field password" type="password" placeholder="Password" name="password" required>
<i class="fa fa-eye icon toggle"></i>
</div>
<div class="input-container">
<i class="fa fa-lock icon"></i>
<input class="input-field" type="password" placeholder="Confirm Password" name="cpass" required>
<i class="fa fa-eye icon"></i>
</div>
</div>
<center><input type="submit" name="register" id="submit" value="Signup" class="btn"></center>
<div class="links">
Already have an account? <a href="login.php">Signin Now</a>
</div>
</form>
</div>
<?php
}
?>
</div>
<script>
const toggle = document.querySelector(".toggle"),
input = document.querySelector(".password");
toggle.addEventListener("click", () => {
if (input.type === "password") {
input.type = "text";
toggle.classList.replace("fa-eye-slash", "fa-eye");
} else {
input.type = "password";
}
})
</script>
</body>
</html>