public static function rememberMe($user) { $token = self::generate_random_128_256_bit(); // generate a token, should be 128 - 256 bit //$u->token = $token; //$u->save(); $cookie = $user . ':' . $token; $mac = hash_hmac('sha256', $cookie, getenv("key")); $cookie .= ':' . $mac; Cookie::set("rememberme", $cookie); }
public function setRememberMe() { // STEP 1: Generate The Hash. $key = rand(1, 100000) . time(); $hash = Criptography::encript($key); // STEP 2: Store the key/hash combination + the session as JSON Array on the database $session = new Sessions(); $session->hash = $key; $session->json_session = json_encode($_SESSION); $session->saveAndGetId(); //Set the cookie with the ID and the cookie with the hash Cookie::set(Config::get("cookieID"), $session); Cookie::set(Config::get("cookieHash"), $hash); }
public static function store($filename, $logMessage, $userinfo = false, $mail = false) { # File name $filename = FILE_PATH . DS . 'logs' . DS . $filename . '.log'; # Extra stuff $extras = ''; $datetime = date('Y-m-d H:i:s'); # Open the handle $fd = fopen($filename, 'a'); # Debug Backtrace $debugBacktrace = debug_backtrace(); $line = $debugBacktrace[1]['line']; $file = $debugBacktrace[1]['file']; # Simple Message $message = preg_replace('/\\s+/', ' ', trim($logMessage)); $log = "\r\n" . 'DATE: ' . $datetime . ' || ACTION: ' . $logMessage . ' || FILE AND LINE: ' . $file . ' - ' . $line; # If wants user info: if ($userinfo) { $session = \Mariana\Framework\Session\Session::display(); $cookie = \Mariana\Framework\Session\Cookie::display(); if ($session) { $extras .= ' || SESSION: ' . $session; } if (isset($cookie)) { $extras .= ' || COOKIES: ' . html_entity_decode($cookie); } $ip = self::getIp(); $uid = self::getUniqueIdentifyer(); $log = "\r\n" . 'DATE: ' . $datetime . ' || IP: ' . $ip . ' || UNIQUE: ' . $uid . ' || ACTION: ' . $logMessage . ' || FILE AND LINE: ' . $file . ' - ' . $line . ' || EXTRA INFO: ' . $extras; } fwrite($fd, $log); fclose($fd); if ($mail) { mail(Config::get('security-report-email-address'), $message, $log); } }