├── .DS_Store
├── .idea
└── workspace.xml
├── README.md
├── activate.php
├── admin.php
├── css
├── bootstrap.css
└── styles.css
├── functions
├── ajax.php
├── db.php
├── functions.php
└── init.php
├── inc
├── footer.php
├── header.php
└── nav.php
├── index.php
├── js
├── bootstrap.js
├── jquery.js
└── scripts.js
├── login.php
├── logout.php
├── recover.php
├── register.php
└── reset.php
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahmedelshaar/Registration-System-Using-PHP-and-MySQL/3be7454fbb05705708f05602b8a3b0942bfccb0a/.DS_Store
--------------------------------------------------------------------------------
/.idea/workspace.xml:
--------------------------------------------------------------------------------
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 | 1592425018732
56 |
57 |
58 | 1592425018732
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
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 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # registration and login form in php and mysql with validation code
2 |
3 | User Registration And Login With PHP MYSQL
4 |
5 | > important concepts and features in this project
6 | * validation and security : back-end php script and show error by php
7 | * secured password hashing (with php hasing algorithm)
8 | * register and Login user
9 | * send account activation link via e-mail
10 | * Implement Email Verification for New Members
11 | * Implement account Recovery for Current Members
12 | * Password reset system and security
13 | * Log out
14 |
15 | > Important Note:
16 |
17 | Change your database username and password and url your website in functions\db.php file.
18 |
19 | # License
20 | This program is free software published under the terms of the GNU [Lesser General Public License](http://www.gnu.org/licenses/lgpl-3.0.html). You can freely use it on commercial or non-commercial websites.
--------------------------------------------------------------------------------
/activate.php:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/admin.php:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/css/styles.css:
--------------------------------------------------------------------------------
1 | body {
2 | padding-top: 90px;
3 | }
4 | .panel-login {
5 | border-color: #ccc;
6 | -webkit-box-shadow: 0px 2px 3px 0px rgba(0,0,0,0.2);
7 | -moz-box-shadow: 0px 2px 3px 0px rgba(0,0,0,0.2);
8 | box-shadow: 0px 2px 3px 0px rgba(0,0,0,0.2);
9 | }
10 | .panel-login>.panel-heading {
11 | color: #00415d;
12 | background-color: #fff;
13 | border-color: #fff;
14 | text-align:center;
15 | }
16 | .panel-login>.panel-heading a{
17 | text-decoration: none;
18 | color: #666;
19 | font-weight: bold;
20 | font-size: 15px;
21 | -webkit-transition: all 0.1s linear;
22 | -moz-transition: all 0.1s linear;
23 | transition: all 0.1s linear;
24 | }
25 | .panel-login>.panel-heading a.active{
26 | color: #029f5b;
27 | font-size: 18px;
28 | }
29 | .panel-login>.panel-heading hr{
30 | margin-top: 10px;
31 | margin-bottom: 0px;
32 | clear: both;
33 | border: 0;
34 | height: 1px;
35 | background-image: -webkit-linear-gradient(left,rgba(0, 0, 0, 0),rgba(0, 0, 0, 0.15),rgba(0, 0, 0, 0));
36 | background-image: -moz-linear-gradient(left,rgba(0,0,0,0),rgba(0,0,0,0.15),rgba(0,0,0,0));
37 | background-image: -ms-linear-gradient(left,rgba(0,0,0,0),rgba(0,0,0,0.15),rgba(0,0,0,0));
38 | background-image: -o-linear-gradient(left,rgba(0,0,0,0),rgba(0,0,0,0.15),rgba(0,0,0,0));
39 | }
40 | .panel-login input[type="text"],.panel-login input[type="email"],.panel-login input[type="password"] {
41 | height: 45px;
42 | border: 1px solid #ddd;
43 | font-size: 16px;
44 | -webkit-transition: all 0.1s linear;
45 | -moz-transition: all 0.1s linear;
46 | transition: all 0.1s linear;
47 | }
48 | .panel-login input:hover,
49 | .panel-login input:focus {
50 | outline:none;
51 | -webkit-box-shadow: none;
52 | -moz-box-shadow: none;
53 | box-shadow: none;
54 | border-color: #ccc;
55 | }
56 | .btn-login {
57 | background-color: #59B2E0;
58 | outline: none;
59 | color: #fff;
60 | font-size: 14px;
61 | height: auto;
62 | font-weight: normal;
63 | padding: 14px 0;
64 | text-transform: uppercase;
65 | border-color: #59B2E6;
66 | }
67 | .btn-login:hover,
68 | .btn-login:focus {
69 | color: #fff;
70 | background-color: #53A3CD;
71 | border-color: #53A3CD;
72 | }
73 | .forgot-password {
74 | text-decoration: underline;
75 | color: #888;
76 | }
77 | .forgot-password:hover,
78 | .forgot-password:focus {
79 | text-decoration: underline;
80 | color: #666;
81 | }
82 |
83 | .btn-register {
84 | background-color: #1CB94E;
85 | outline: none;
86 | color: #fff;
87 | font-size: 14px;
88 | height: auto;
89 | font-weight: normal;
90 | padding: 14px 0;
91 | text-transform: uppercase;
92 | border-color: #1CB94A;
93 | }
94 | .btn-register:hover,
95 | .btn-register:focus {
96 | color: #fff;
97 | background-color: #1CA347;
98 | border-color: #1CA347;
99 | }
100 |
101 |
102 |
103 | /* Code Page */
104 |
105 | #code {
106 |
107 | height: 60px;
108 | width: 50%;
109 | margin: 0 auto;
110 | font-size: 40px;
111 |
112 | }
113 |
114 |
115 |
116 |
117 |
--------------------------------------------------------------------------------
/functions/ajax.php:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ahmedelshaar/Registration-System-Using-PHP-and-MySQL/3be7454fbb05705708f05602b8a3b0942bfccb0a/functions/ajax.php
--------------------------------------------------------------------------------
/functions/db.php:
--------------------------------------------------------------------------------
1 | query($query);
16 | }
17 | createTabel();
18 |
19 | function escape($string)
20 | {
21 | global $con;
22 | return mysqli_real_escape_string($con, $string);
23 | }
24 |
25 |
26 | function row_count($result)
27 | {
28 | return mysqli_num_rows($result);
29 | }
30 |
31 | function query($query)
32 | {
33 | global $con;
34 | return mysqli_query($con, $query);
35 | }
36 |
37 | function confirm($result)
38 | {
39 | global $con;
40 | if (!$result) {
41 | die("QUERY FAILED " . mysqli_error($con));
42 | }
43 | }
--------------------------------------------------------------------------------
/functions/functions.php:
--------------------------------------------------------------------------------
1 | 20) {
80 | $errors[] = "Your Username cannot be bigger then 20 characters";
81 | }
82 | if (email_exists($email)) {
83 | $errors[] = "Sorry that Email is already is taken";
84 | }
85 | if (user_exists($username)) {
86 | $errors[] = "Sorry that Username is already is taken";
87 | }
88 | if (strlen($password) < 8) {
89 | $errors[] = "Your Password cannot be less then 8 characters";
90 | }
91 | if ($password != $confirm_password) {
92 | $errors[] = "The password was not confirmed correctly";
93 | }
94 | if (!empty($errors)) {
95 | foreach ($errors as $error) {
96 | echo '' . $error . '
97 |
';
99 | }
100 | } else {
101 | $first_name = filter_var($first_name, FILTER_SANITIZE_STRING);
102 | $last_name = filter_var($last_name, FILTER_SANITIZE_STRING);
103 | $username = filter_var($username, FILTER_SANITIZE_STRING);
104 | $email = filter_var($email, FILTER_SANITIZE_EMAIL);
105 | $password = filter_var($password, FILTER_SANITIZE_STRING);
106 | $password = password_hash($password,PASSWORD_DEFAULT );
107 | createuser($first_name, $last_name, $username, $email, $password);
108 | }
109 | }
110 | }
111 |
112 | function createuser($first_name, $last_name, $username, $email, $password)
113 | {
114 | global $url;
115 | $first_name = escape($first_name);
116 | $last_name = escape($last_name);
117 | $username = escape($username);
118 | $email = escape($email);
119 | $password = escape($password);
120 | $password = password_hash($password,PASSWORD_DEFAULT );
121 | $token = md5($username . microtime());
122 | $sql = "INSERT INTO users(first_name,last_name,username,email,password,token,activition) ";
123 | $sql .= "VALUES('$first_name','$last_name','$username','$email','$password','$token',0)";
124 | confirm(query($sql));
125 | set_message('Please Check Your Email or Spam Folder For activation Link');
126 | $subject = "Activate Account";
127 | $msg = "Please Click the link below to Activate Your Account
128 | $url/activate.php?email=$email&code=$token";
129 | $headers = "From: x24web@gmail.com";
130 | send_email($email, $subject, $msg, $headers);
131 | redirect('index.php');
132 | }
133 |
134 | function send_email($email, $subject, $msg, $headers)
135 | {
136 | return mail($email, $subject, $msg, $headers);
137 | }
138 |
139 | function activate_user()
140 | {
141 | if ($_SERVER['REQUEST_METHOD'] == "GET") {
142 | $email = clean($_GET['email']);
143 | $code = clean($_GET['code']);
144 | $email = filter_var($email, FILTER_SANITIZE_EMAIL);
145 | $code = filter_var($code, FILTER_SANITIZE_STRING);
146 | $query = "SELECT id FROM users WHERE email='$email' AND token='$code'";
147 | $queryEmail = "SELECT id FROM users WHERE email='$email'";
148 | $result = query($query);
149 | $resultEmail = query($queryEmail);
150 | confirm($result);
151 | confirm($resultEmail);
152 |
153 | if (row_count($result) == 1) {
154 | $query = "UPDATE users SET activition = 1, token = 0 Where email='$email' and token='$code'";
155 | confirm(query($query));
156 | set_message("Your Account has been Activated Please Login
");
157 | redirect('login.php');
158 | } else {
159 | if (row_count($resultEmail) == 1) {
160 | set_message("Your account is already activated
");
161 | redirect('login.php');
162 | } else {
163 | set_message("The activation link is incorrect. Please create an account
");
164 | redirect('register.php');
165 | }
166 | }
167 | }
168 | }
169 |
170 | function validate_user_login()
171 | {
172 | $errors = [];
173 | if ($_SERVER['REQUEST_METHOD'] == "POST") {
174 | $email = clean($_POST['email']);
175 | $password = clean($_POST['password']);
176 | $remember = clean(isset($_POST['remember']));
177 | $password = password_hash($password,PASSWORD_DEFAULT );
178 | if (empty($email)) {
179 | $errors[] = "Email field cannot be empty";
180 | }
181 | if (empty($password)) {
182 | $errors[] = "Password field cannot be empty";
183 | }
184 | if (empty($errors)) {
185 | if (user_login($email, $password, $remember)) {
186 | redirect('admin.php');
187 | } else {
188 | $errors[] = "your email or password is incorrect. please try again";
189 | }
190 | }
191 | if (!empty($errors)) {
192 | foreach ($errors as $error) {
193 | echo '' . $error . '
194 |
';
196 | }
197 | }
198 | }
199 |
200 | }
201 |
202 | function user_login($email, $password, $remember)
203 | {
204 | $password = filter_var($password, FILTER_SANITIZE_STRING);
205 | $password = password_hash($password,PASSWORD_DEFAULT );
206 | $email = filter_var($email, FILTER_SANITIZE_EMAIL);
207 | $remember = filter_var($remember, FILTER_SANITIZE_STRING);
208 |
209 | $query = "SELECT id FROM users WHERE email='$email' AND password='$password'";
210 | $result = query($query);
211 | if (row_count($result) == 1) {
212 | if ($remember == "1") {
213 | setcookie('email', $email, time() + (86400 * 30));
214 | }
215 | $_SESSION['email'] = $email;
216 | return true;
217 | } else {
218 | return false;
219 | }
220 | }
221 |
222 | function login_check_admin()
223 | {
224 | if (isset($_SESSION['email']) || isset($_COOKIE['email'])) {
225 | return true;
226 | } else {
227 | redirect('index.php');
228 | }
229 | }
230 |
231 | function login_check_pages()
232 | {
233 | if (isset($_SESSION['email']) || isset($_COOKIE['email'])) {
234 | redirect('admin.php');
235 | }
236 | }
237 |
238 | function recover()
239 | {
240 | global $url;
241 | if ($_SERVER['REQUEST_METHOD'] == "POST") {
242 | if (isset($_POST['cancel-submit'])) {
243 | redirect('login.php');
244 | }
245 | if (isset($_POST['recover-submit'])) {
246 | $email = $_POST['email'];
247 | $email = filter_var($email, FILTER_SANITIZE_EMAIL);
248 | $query = "SELECT id FROM users WHERE email='$email'";
249 | $result = query($query);
250 | if (row_count($result) == 1) {
251 | $token = token_generator();
252 | $query = "UPDATE users set token='$token' WHERE email='$email'";
253 | query($query);
254 | set_message('Please Check Your Email or Spam Folder For Recover Link');
255 | $subject = "Activate Account";
256 | $msg = "Please Click the link below to Activate Your Account
257 | $url/code.php?email=$email&code=$token";
258 | $headers = "From: x24web@gmail.com";
259 | send_email($email, $subject, $msg, $headers);
260 | redirect('index.php');
261 | } else {
262 | set_message("This Email does not Exist");
263 | redirect('recover.php');
264 | }
265 | }
266 | echo "";
267 | display_message();
268 | echo "
";
269 | }
270 | }
271 |
272 | function check_code()
273 | {
274 | if ($_SERVER['REQUEST_METHOD'] == "GET")
275 | {
276 | $email = $_GET['email'];
277 | $token = $_GET['token'];
278 | $email = filter_var($email, FILTER_SANITIZE_EMAIL);
279 | $token = filter_var($token, FILTER_SANITIZE_STRING);
280 | $query = "SELECT id FROM users WHERE email='$email' AND token='$token'";
281 | $result = query($query);
282 | if (row_count($result) == 1) {
283 | return true;
284 | }
285 | }
286 | if ($_SERVER['REQUEST_METHOD'] == "POST"){
287 | if(isset($_POST['reset-password-submit'])){
288 | $email = $_GET['email'];
289 | $password = $_POST['password'];
290 | $confirm_password = $_POST['confirm_password'];
291 |
292 | $email = filter_var($email, FILTER_SANITIZE_EMAIL);
293 | $password = filter_var($password, FILTER_SANITIZE_STRING);
294 | $confirm_password = filter_var($confirm_password, FILTER_SANITIZE_STRING);
295 |
296 | if($password == $confirm_password){
297 | $password = password_hash($password,PASSWORD_DEFAULT );
298 | $query = "UPDATE users set password='$password', token='0' WHERE email='$email'";
299 | query($query);
300 | set_message('The password has been updated. Can Be Login Now
');
301 | redirect('login.php');
302 | }
303 | }
304 | }
305 | }
--------------------------------------------------------------------------------
/functions/init.php:
--------------------------------------------------------------------------------
1 |
2 |