public function offsetExists($key) : bool { return is_string($key) && (isset($this->mData[$key]) || isset($this->mData[Crypt::hash($this->mPrefix . $key)])); }
private function handleAuthRequest() { $status = false; /* * Are we logging in or out? */ if (Runtime::$GET["action"] == "login") { /* * If not already logged-in, let's log the user in */ if (!Auth::isLoggedIn()) { $user = Runtime::$POST["username"]; $passwd = Runtime::$POST["password"]; $token = Runtime::$POST["token"]; if (!empty($token) && strcmp($token, Runtime::$SESSION["_im_login_token"]) === 0) { if (!empty($user) && !empty($passwd)) { Auth::login($user, $passwd); } $status = Auth::isLoggedIn(); if (!$status && Runtime::$SYSTEM["REQUEST_CONTENT"] == "json") { Runtime::$SESSION["_im_login_token"] = Crypt::encode(Crypt::password()); } else { Runtime::$SESSION->remove("_im_login_token"); } } } } elseif (Runtime::$GET["action"] == "logout") { /* * If not already logged-out, let's log the user out */ if (Auth::isLoggedIn()) { Auth::logout(); } $status = !Auth::isLoggedIn(); } /* * If the client is asking for JSON content, we provide a JSON object * with the status of the request. */ if (Runtime::$SYSTEM["REQUEST_CONTENT"] == "json") { echo json_encode(["status" => $status, "token" => Runtime::$SESSION["_im_login_token"]]); /* * If the client is asking for html content, * e.g. the request is a regular post/load request and not an ajax request. */ } elseif (Auth::isLoggedIn()) { Router::request("/"); /* * Regular post/load request, user is not logged-in. * Either wrong password/username was supplied, or this was a * logout request. Either way, show the login form again. */ } else { $this->buildLoginForm(); } }
public function getRaw(string $key, string $default = null, string $encKey = null) { $result = $this->selectCache($key); if ($result !== null && $result->numRows() > 0) { $row = $result->fetch(); if ($encKey !== null) { $data = Crypt::decrypt($row[0], $encKey, true); } else { $data = $row[0]; } } if ($result !== null) { $result->destroy(); } return $data ?? $default; }
/** @ignore */ protected function read(string $key, string $encKey = null) { $fileKey = sha1($key); // Key could contain non-filename characters $cacheFile = $this->mPath . "{$fileKey}.cache"; $data = null; if (is_file($cacheFile)) { if ($encKey !== null) { $data = Crypt::decrypt(file_get_contents($cacheFile), $encKey, false); } else { $data = file_get_contents($cacheFile); } } return $data; }
public function getRaw(string $key, string $default = null, string $encKey = null) { $data = $this->mConnection->get($key); $status = $this->mConnection->getResultCode(); if ($status !== Memcached::RES_NOTFOUND) { if ($encKey !== null) { $data = Crypt::decrypt($data, $encKey, false); } return $data; } return $default; }
/** @ignore */ public function writeBack() { if (!Runtime::hasLock("session")) { if ($this->mSessReady && !in_array(Runtime::$SYSTEM["REQUEST_CLIENT"], ["terminal", "crawler"])) { $data = serialize($this->mData); if (Runtime::$SETTINGS->getBoolean("SESSION_ENCRYPT_DATA")) { $cryptKey = Runtime::$SETTINGS->getString("SECURITY_PASSWD"); if (!empty($cryptKey)) { $data = Crypt::encrypt($data, $cryptKey, true); } } $this->mSessHandler->write($data); } $this->mSessReady = false; } else { Runtime::addLockCallback("session", [$this, "writeBack"]); } }