-
Notifications
You must be signed in to change notification settings - Fork 0
/
1registration.php
163 lines (142 loc) · 4.82 KB
/
1registration.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
session_start();
require("0conn.php");
try {
$pdo = new PDO("mysql:host=$host;dbname=$database", $username, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
die("Error: " . $e->getMessage());
}
$errors = [];
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = $_POST["username"];
$email = $_POST["email"];
$password = $_POST["password"];
$confirm_password = $_POST["confirm_password"];
if ($password != $confirm_password) {
$errors[] = "Password and Confirm Password do not match.";
}
if (strlen($password) < 8) {
$errors[] = "Password must be at least 8 characters long.";
}
if (empty($errors)) {
$password_hash = password_hash($password, PASSWORD_BCRYPT);
$stmt = $pdo->prepare("INSERT INTO users (username, email, password) VALUES (?, ?, ?)");
$stmt->execute([$username, $email, $password_hash]);
header("Location: 3login.php");
exit();
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Registration</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<style>
body {
background-color: #ededed;
color: #000;
}
.container {
display: flex;
max-width: 800px;
margin: 100px auto;
border-radius: 8px;
overflow: hidden;
}
.left-panel {
flex: 1;
background: url('picture.jpg');
background-size: cover;
background-position: center;
border-radius: 8px 0 0 8px;
padding: 20px;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.right-panel {
flex: 1;
padding: 20px;
border-radius: 0 8px 8px 0;
background-color: #fff;
}
h2 {
text-align: center;
color: #000;
}
form {
margin-top: 20px;
}
label {
font-weight: bold;
color: #000;
}
.form-group {
margin-bottom: 20px;
}
button {
width: 100%;
background-color: #000;
color: #fff;
}
.btn {
background-color: #fff;
color: #000;
}
img {
width: 100%;
height: auto;
max-height: 500px;
filter: grayscale(100%);
border-radius: 8px;
}
.login-link {
margin-top: 20px;
text-align: center;
}
</style>
</head>
<body>
<div class="container">
<div class="left-panel"></div>
<div class="right-panel">
<h2>Registration</h2>
<?php
foreach ($errors as $error) {
echo '<div class="alert alert-danger" role="alert">' . $error . '</div>';
}
?>
<form action="1registration.php" method="post" onsubmit="return validateForm()">
<div class="form-group">
<label for="username">Username:</label>
<input type="text" name="username" class="form-control" required>
</div>
<div class="form-group">
<label for="email">Email:</label>
<input type="email" name="email" class="form-control" required>
</div>
<div class="form-group">
<label for="password">Password:</label>
<input type="password" name="password" id="password" class="form-control" required>
</div>
<div class="form-group">
<label for="confirm_password">Confirm Password:</label>
<input type="password" name="confirm_password" class="form-control" required>
</div>
<button type="submit" class="btn btn-primary">Register</button>
</form>
<div class="login-link">
<p>Already have an account? <a href="3login.php">Login</a></p>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.0.8/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
</html>