if (!($jdata = json_decode($data, true))) { throw new RuntimeException("Unable to parse input."); } if (empty($jdata["credentials"])) { throw new RuntimeException("Received credentials are missing."); } // Read credentials $cred_obj = explode(" ", base64_decode($jdata['credentials'])); if (count($cred_obj) < 2) { throw new RuntimeException("Received credentials are malformed."); } // This is where you normally handle the call, i.e.. $res = Api::handleRequest($jdata); // Username and passphrase successfully read. $username = $cred_obj[0]; $passphrase = $cred_obj[1]; // Set asymmetric key to be used in future communication $session = Session::getInstance(); $session->set(Session::TRANSPORT_KEY, Encryption::genGarbage(Session::KEYSIZE)); // Clear login key $session->set(Captcha::KEY_LOGIN, null); // Let's say that everything went well and Citizen $username was loaded successfully. $res = array("id" => 123, "username" => $username, Session::STORAGE_KEY => base64_encode(Session::getStorageKey()), Session::TRANSPORT_KEY => base64_encode($session->get(Session::TRANSPORT_KEY))); // This is where you normally pass $res (Api::handleRequest()) to whatever renderer is available. /* Output */ $output = json_encode(array("result" => $res)); die(Encryption::enc($output, $key)); } catch (Exception $e) { $output = json_encode(array("error" => array("code" => 1, "message" => $e->getMessage()))); trigger_error($e->getMessage()); die(Encryption::enc($output, $key)); }
/** * The majority of this page is taken from README.md * Attempt to load and parse it. Should it fail, abort the render of * this page and suggest heading to one of my other pages. */ use Michelf\MarkdownExtra; require_once '../third/php-markdown/Michelf/Markdown.inc.php'; require_once '../third/php-markdown/Michelf/MarkdownExtra.inc.php'; $readme = MarkdownExtra::defaultTransform(file_get_contents("README.md")); if (strlen($readme) < 1024) { die("README.md missing. Go to https://richardkszabo.me or https://github.com/rszabo"); } /** * Display our session-data key */ $key_s = Session::getStorageKey(); ?> <!DOCTYPE html5> <html lang="en"> <head> <title>Égalité</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="author" content="Written by Richard K. Szabó/SPECIMEN"/> <meta name="description" content="Example of Specimen login system"/> </head> <body class="page_login">