3 * @file /src/Core/Authentication.php
6 namespace Friendica\Core;
8 use Friendica\BaseObject;
9 use Friendica\Util\BaseURL;
12 * Handle Authentification, Session and Cookies
14 class Authentication extends BaseObject
17 * @brief Calculate the hash that is needed for the "Friendica" cookie
19 * @param array $user Record from "user" table
21 * @return string Hashed data
22 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
24 public static function getCookieHashForUser($user)
26 return(hash("sha256", Config::get("system", "site_prvkey") .
32 * @brief Set the "Friendica" cookie
35 * @param array $user Record from "user" table
36 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
38 public static function setCookie($time, $user = [])
41 $time = $time + time();
45 $value = json_encode(["uid" => $user["uid"],
46 "hash" => self::getCookieHashForUser($user),
47 "ip" => defaults($_SERVER, 'REMOTE_ADDR', '0.0.0.0')]);
52 setcookie("Friendica", $value, $time, "/", "", (Config::get('system', 'ssl_policy') == BaseUrl::SSL_POLICY_FULL), true);
56 * @brief Kills the "Friendica" cookie and all session data
58 public static function deleteSession()
60 self::setCookie(-3600); // make sure cookie is deleted on browser close, as a security measure