-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsignup.php
179 lines (156 loc) · 4.74 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
<!DOCTYPE html>
<html>
<head>
<title>Create Account | Admin Panel</title>
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<style>
/* Define colors */
:root {
--twitter-blue: #1DA1F2;
--twitter-blue-light: #E8F5FE;
--twitter-gray: #657786;
--twitter-white: #FFFFFF;
}
/* Global styles */
body {
margin: 0;
padding: 0;
font-family: 'Roboto', sans-serif;
}
/* Header styles */
header {
background-color: var(--twitter-blue);
color: var(--twitter-white);
padding: 10px;
}
nav ul {
list-style: none;
margin: 0;
padding: 0;
}
nav li {
display: inline-block;
margin-right: 20px;
}
nav li:last-child {
margin-right: 0;
}
nav a {
color: var(--twitter-white);
text-decoration: none;
}
/* Form styles */
form {
background-color: var(--twitter-white);
border-radius: 8px;
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.2);
margin: 40px auto;
max-width: 400px;
padding: 40px;
}
form h2 {
color: var(--twitter-gray);
font-size: 24px;
margin-bottom: 20px;
}
form label {
color: var(--twitter-gray);
display: block;
font-size: 16px;
margin-bottom: 10px;
}
form input[type="text"],
form input[type="password"] {
border: 1px solid var(--twitter-gray);
border-radius: 4px;
font-size: 16px;
padding: 8px;
width: 100%;
}
form button {
background-color: var(--twitter-blue);
border: none;
border-radius: 50px;
color: var(--twitter-white);
font-size: 18px;
margin-top: 20px;
padding: 10px 20px;
text-decoration: none;
transition: all 0.3s ease;
}
form button:hover {
background-color: var(--twitter-blue-light);
}
/* Footer styles */
footer {
background-color: var(--twitter-blue);
color: var(--twitter-white);
padding: 10px;
text-align: center;
position: fixed;
bottom: 0;
left: 0;
width: 100%;
}
footer p {
margin: 0;
font-size: 14px;
}
</style>
</head>
<body>
<?php include('header.php'); ?>
<?php
// Define the filename to use for the user data file
$filename = 'users.txt';
// Check if the form was submitted
if (isset($_POST['username']) && isset($_POST['password']) && isset($_POST['confirm_password'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$confirm_password = $_POST['confirm_password'];
// Check if the username and password meet the required criteria
if (strlen($username) >= 6 && strlen($password) >= 8 && preg_match('/[A-Za-z]/', $password) && preg_match('/[0-9]/', $password)) {
// Check if the password and confirm password fields match
if ($password === $confirm_password) {
// Hash the password for storage
$hashed_password = password_hash($password, PASSWORD_DEFAULT);
// Create an array of user data
$user_data = array(
'username' => $username,
'hashed_password' => $hashed_password
);
// Encode the user data as JSON
$user_json = json_encode($user_data);
// Open the user data file for appending
$file_handle = fopen($filename, 'a');
// Write the user data to the file
fwrite($file_handle, $user_json . "\n");
// Close the file handle
fclose($file_handle);
// Redirect the user to the login page
header('Location: login.php');
exit;
} else {
$message = 'Passwords do not match';
}
} else {
$message = 'Username or password does not meet requirements';
}
}
?>
<form action="signup.php" method="post">
<h2>Create account</h2>
<?php if (!empty($message)) { ?>
<p><?php echo $message; ?></p>
<?php } ?>
<label for="username">Username:</label>
<input type="text" name="username" id="username" required>
<label for="password">Password:</label>
<input type="password" name="password" id="password" required>
<label for="confirm_password">Confirm password:</label>
<input type="password" name="confirm_password" id="confirm_password" required>
<button type="submit">Create account</button>
</form>
<?php include('footer.php'); ?>
</body>
</html>