34 return isset($_SESSION[$key]) ? $_SESSION[$key] :
null;
44 $_SESSION[$key] = $value;
53 if (isset($_SESSION[$key])) {
54 unset($_SESSION[$key]);
67 return $this->
getData(
'userId');
75 if (!isset($userId) || empty($userId)) {
79 }
else if ($userId != $this->
getData(
'userId')) {
81 $this->user = $userDao->getById($userId);
82 if (!isset($this->user)) {
86 $this->
setData(
'userId', $userId);
94 return $this->
getData(
'ipAddress');
102 $this->
setData(
'ipAddress', $ipAddress);
110 return $this->
getData(
'userAgent');
118 $this->
setData(
'userAgent', $userAgent);
126 return $this->
getData(
'created');
134 $this->
setData(
'created', $created);
142 return $this->
getData(
'lastUsed');
150 $this->
setData(
'lastUsed', $lastUsed);
158 return $this->
getData(
'remember');
166 $this->
setData(
'remember', $remember);
190 return $this->
getData(
'domain');
198 $this->
setData(
'domain', $data);
215 if (!is_array($csrf) || time() > $csrf[
'timestamp'] + (60*60)) {
217 if (function_exists(
'openssl_random_pseudo_bytes')) $data = openssl_random_pseudo_bytes(128);
218 elseif (function_exists(
'random_bytes')) $data = random_bytes(128);
219 else $data = sha1(mt_rand());
224 $algos = hash_algos();
225 foreach (array(
'sha256',
'sha1',
'md5') as $algo) {
226 if (in_array($algo, $algos)) {
227 $token = hash_hmac($algo, $data, $salt);
230 if (!$token) $token = md5($data . $salt);
233 'timestamp' => time(),
238 $csrf[
'timestamp'] = time();
241 return $csrf[
'token'];