Example #1
0
 public function testCreateAndDestroy()
 {
     Session::create(__FILE__);
     $instance1 = Session::getCurrent();
     Session::create(__FILE__);
     $instance2 = Session::getCurrent();
     $instance3 = Session::getCurrent();
     Session::destroy();
     $instance4 = Session::getCurrent();
     $this->assertSame($instance1, $instance4);
     $this->assertSame($instance2, $instance3);
     $this->assertTrue($instance1 !== $instance2);
 }
Example #2
0
 * @warning   Only JSON-formatted data should be displayed.
 *
 *
 * This is a simple example of how to respond to a login request.
 *
 */
$auto_login = false;
require "../../include/iq.php";
try {
    /* Validate body */
    $body = file_get_contents('php://input');
    if (!$body && !isset($_REQUEST['_'])) {
        throw new RuntimeException("404");
    }
    /* Input is encrypted with the hashed captcha! */
    $key = base64_encode(Session::getCurrent()->get(Captcha::KEY_LOGIN));
    // Attempt to decrypt
    if (!($data = Encryption::dec($_REQUEST["_"], $key))) {
        throw new RuntimeException("Unable to decrypt received data, please check your local key or verification code.");
    }
    // Check JSON
    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.");