CSC Curling | Log In <?php require_once '../scripts/main.php'; if (isset($_SESSION['auth']) || isset($_SESSION['uid']) || isset($_SESSION['un']) || isset($_SESSION['email'])) { gotopage("/"); } global $error; global $conn; $error = []; $errorMappings = ["password" => "Please enter a password", "username" => "Please enter a username or email address", "invalid" => "Your email address, username, and/or password is incorrect", "dberror" => "Uh-Oh, we're having an issue with our database. Please try again later"]; check_cond(!DBCheck($conn), "dberror"); cCS($_POST['password'], "password"); cCS($_POST['username'], "username"); function check_cond($assertion, $errort) { global $error; $error[$errort] = $assertion; return $assertion; } function cCS($assertion, $error) { return check_cond(isset($assertion), $error); } if ($error['password'] || $error['username']) { $formattedError = ""; foreach ($error as $key => $value) { if (!$value && isset($errorMappings[$key])) { $formattedError .= $errorMappings[$key] . "\n"; } } $useJSON = isset($_POST['from']) && $_POST['from'] == 'jquery';
if (cCS($_POST['username'], "username")) { $username = trim($_POST['username']); cCL($username, 65, false, "usernamel"); cCL($username, 3, true, "usernames"); if (!DBCheck($conn)) { $query = sprintf("SELECT * FROM users WHERE username ='******';", $conn->real_escape_string($username)); $result = $conn->query($query); $rows = $result === false ? !check_cond(false, "dberror") : $result->num_rows; check_cond($rows < 1, "usernamet"); } } if (cCS($_POST['email'], "email")) { $email = trim($_POST['email']); cCL($email, 65, false, "emaill"); check_cond(!!filter_var($email, FILTER_VALIDATE_EMAIL), "emailv"); if (!DBCheck($conn)) { $query = sprintf("SELECT * FROM users WHERE email ='%s';", $conn->real_escape_string($email)); $result = $conn->query($query); $rows = $result === false ? !check_cond(false, "dberror") : $result->num_rows; check_cond($rows < 1, "emailt"); } } function check_cond($assertion, $errort) { global $error; $error[$errort] = $assertion; return $assertion; } function cCS($assertion, $error) { return check_cond(isset($assertion), $error);