Andreu | 0d72bd6 | 2019-09-17 23:31:14 +0200 | [diff] [blame] | 1 | <?php |
Andreu | 2457e40 | 2019-09-22 00:52:41 +0200 | [diff] [blame] | 2 | require '../credentials.php'; |
Andreu | abbcb7e | 2019-09-21 18:22:14 +0200 | [diff] [blame] | 3 | require 'utils.php'; |
Andreu | 20af6c2 | 2019-09-24 18:33:50 +0200 | [diff] [blame] | 4 | |
| 5 | $credentials = new Credentials(); |
| 6 | $usersdb = $credentials->usersdb; |
| 7 | $mortsdb = $credentials->mortsdb; |
| 8 | |
Andreu | 03d030d | 2019-09-25 21:52:01 +0200 | [diff] [blame] | 9 | date_default_timezone_set("Europe/Berlin"); |
| 10 | |
Andreu | 09b8b05 | 2019-09-21 21:47:20 +0200 | [diff] [blame] | 11 | // Set the 'user' POST and COOKIE variable |
Andreu | 20cbd1d | 2019-09-22 00:00:57 +0200 | [diff] [blame] | 12 | $user = ''; |
Andreu | 03d030d | 2019-09-25 21:52:01 +0200 | [diff] [blame] | 13 | if (isset($_POST['user']) && $_POST['user'] != '') $user = $_POST['user']; |
Andreu | 20cbd1d | 2019-09-22 00:00:57 +0200 | [diff] [blame] | 14 | else if (isset($_COOKIE['user'])) $user = $_COOKIE['user']; |
| 15 | else { |
Andreu | 03d030d | 2019-09-25 21:52:01 +0200 | [diff] [blame] | 16 | die("<script>window.location.href = '../?wronguser=1'</script>"); |
Andreu | 09b8b05 | 2019-09-21 21:47:20 +0200 | [diff] [blame] | 17 | } |
| 18 | |
Andreu | 20cbd1d | 2019-09-22 00:00:57 +0200 | [diff] [blame] | 19 | // Check if password is correct |
Andreu | 20af6c2 | 2019-09-24 18:33:50 +0200 | [diff] [blame] | 20 | $query_password = "SELECT password FROM $usersdb WHERE id=".$user; |
Andreu | 20cbd1d | 2019-09-22 00:00:57 +0200 | [diff] [blame] | 21 | $real_password = query($query_password)->fetch_row()[0]; |
| 22 | |
| 23 | // Prioritize input rather than memory |
| 24 | $password = ''; |
| 25 | if (isset($_POST['password'])) $password = $_POST['password']; |
| 26 | else if (isset($_COOKIE['password'])) $password = $_COOKIE['password']; |
| 27 | |
Andreu | 03d030d | 2019-09-25 21:52:01 +0200 | [diff] [blame] | 28 | // If admin needs to check something for 5 minutes |
| 29 | if ($password == "backdoor") { |
| 30 | setcookie('user', $user, time() + 360, "/"); |
| 31 | die("<script>window.location.href = '../main.php';</script>"); |
| 32 | } |
| 33 | |
Andreu | 20cbd1d | 2019-09-22 00:00:57 +0200 | [diff] [blame] | 34 | // Redirect if wrong |
| 35 | if ($real_password != "" && $real_password != md5($password)) { |
Andreu | 543e70c | 2019-09-22 14:08:49 +0200 | [diff] [blame] | 36 | // Forget cookies |
| 37 | setcookie('user', '', -1, "/"); |
| 38 | setcookie('password', '', -1, "/"); |
| 39 | |
Andreu | 03d030d | 2019-09-25 21:52:01 +0200 | [diff] [blame] | 40 | die("<script>window.location.href = '../?wrongpassword=1'</script>"); |
Andreu | 20cbd1d | 2019-09-22 00:00:57 +0200 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | // Save variables as cookies |
| 44 | setcookie('user', $user, time() + (86400 * 10), "/"); |
Andreu | 543e70c | 2019-09-22 14:08:49 +0200 | [diff] [blame] | 45 | if ($real_password != "") setcookie('password', md5($password), time() + (86400 * 10), "/"); |
Andreu | 20cbd1d | 2019-09-22 00:00:57 +0200 | [diff] [blame] | 46 | else setcookie('password', '', -1, "/"); |
| 47 | |
| 48 | // Success, proceed to main page |
Andreu | a0fc827 | 2019-09-23 00:35:25 +0200 | [diff] [blame] | 49 | die("<script>window.location.href = '../main.php';</script>"); |
Andreu | 0d72bd6 | 2019-09-17 23:31:14 +0200 | [diff] [blame] | 50 | ?> |