0) { // Compare doubly hashes password input with saved hash if(isset($_POST["pw"])) { $postinput = hash('sha256',hash('sha256',$_POST["pw"])); if($postinput == $pwhash) { $_SESSION["hash"] = $pwhash; // Login successful, redirect the user to the homepage to discard the POST request if ($_SERVER['REQUEST_METHOD'] === 'POST' && $_SERVER['QUERY_STRING'] === 'login') { header('Location: index.php'); exit(); } $auth = true; } else { $wrongpassword = true; } } // Compare auth hash with saved hash else if (isset($_SESSION["hash"])) { if($_SESSION["hash"] == $pwhash) $auth = true; } // API can use the hash to get data without logging in via plain-text password else if (isset($api) && isset($_GET["auth"])) { if($_GET["auth"] == $pwhash) $auth = true; } else { // Password or hash wrong $auth = false; } } else { // No password set $auth = true; } ?>