use MinehubsStudios\backend\Database; use MinehubsStudios\backend\Request; use MinehubsStudios\backend\Session; use PDO; use DateMalformedStringException; use DateTime; use Random\RandomException; class RememberMe { /** * @var Database */ private Database $database; /** * @var Request */ private Request $request; /** * @var Session * */ private Session $session; /** * REMEMBER ME CONSTRUCTOR. * * @param Database $database * @param Request $request * @param Session $session */ public function __construct(Database $database, Request $request, Session $session) { $this -> database = $database; $this -> request = $request; $this -> session = $session; } /** * SECURELY HANDLES 'Remember Me' COOKIE AUTHENTICATION. * * @return void * * @throws DateMalformedStringException * @throws RandomException */ public function authenticate(): void { if (!isset($_COOKIE['remember'])) { $this -> request -> redirectToLogin(); } $remember_token = $_COOKIE['remember']; // FETCH STORED TOKEN & EXPIRY FROM DB. $statement = $this -> database -> pdo -> prepare("SELECT users_id, remember_token, remember_expiry, users_name, users_role FROM users WHERE remember_token IS NOT NULL"); $statement -> execute(); $user = $statement -> fetch(PDO::FETCH_ASSOC); // VALIDATE TOKEN & EXPIRE. if (!$user || !isset($user['remember_token'], $user['remember_expiry']) || !is_string($remember_token) || !is_string($user['remember_token']) || !password_verify($remember_token, $user['remember_token'])) { $this -> clear(); $this -> request -> redirectToLogin(); } $expiry_time = is_string($user['remember_expiry']) ? $user['remember_expiry'] : '1970-01-01 00:00:00'; if (new DateTime() > new DateTime($expiry_time)) { $this -> clear(); $this -> request -> redirectToLogin(); } // STORE USER DATA. session_regenerate_id(true); $this -> session -> set("userid", $user['users_id']); $this -> session -> set("name", $user["users_name"]); $this -> session -> set("role", $user["users_role"]); // REFRESH 'Remember Me' EXPIRY. $this -> set($user['users_id']); } /** * SET 'Remember Me' TOKEN FOR USER. * * @param int $user_id - THE USER'S UNIQUE ID. * * @return void * * @throws RandomException */ public function set(int $user_id): void { $new_token = bin2hex(random_bytes(32)); $hashed_token = password_hash($new_token, PASSWORD_ARGON2ID); $expiry_time = new DateTime('+7 days') -> format('Y-m-d H:i:s'); $statement = $this -> database -> pdo -> prepare("UPDATE users SET remember_token = :token, remember_expiry = :expiry WHERE users_id = :id"); $statement -> execute(['token' => $hashed_token, 'expiry' => $expiry_time, 'id' => $user_id]); setcookie('remember', $new_token, [ 'expires' => strtotime('+7 days'), 'httponly' => true, 'secure' => isset($_SERVER['HTTPS']), 'samesite' => 'Strict' ]); } /** * CLEARS 'Remember Me' COOKIE & DB TOKEN. * * @return void */ private function clear(): void { setcookie('remember', '', time() - 3600, '/', '', isset($_SERVER['HTTPS']), true); $statement = $this -> database -> pdo -> prepare("UPDATE users SET remember_token = NULL, remember_expiry = NULL WHERE users_id = ?"); $statement -> execute([$this -> session -> get('userid')]); } } Warning: session_name(): Session name cannot be changed after headers have already been sent in /customers/a/5/e/minehubsstudios.com/httpd.www/backend/Session.php on line 55 Warning: ini_set(): Session ini settings cannot be changed after headers have already been sent in /customers/a/5/e/minehubsstudios.com/httpd.www/backend/Session.php on line 57 Warning: ini_set(): Session ini settings cannot be changed after headers have already been sent in /customers/a/5/e/minehubsstudios.com/httpd.www/backend/Session.php on line 58 Warning: ini_set(): Session ini settings cannot be changed after headers have already been sent in /customers/a/5/e/minehubsstudios.com/httpd.www/backend/Session.php on line 59 Warning: ini_set(): Session ini settings cannot be changed after headers have already been sent in /customers/a/5/e/minehubsstudios.com/httpd.www/backend/Session.php on line 60 Warning: session_set_cookie_params(): Session cookie parameters cannot be changed after headers have already been sent in /customers/a/5/e/minehubsstudios.com/httpd.www/backend/Session.php on line 62 Warning: session_start(): Session cannot be started after headers have already been sent in /customers/a/5/e/minehubsstudios.com/httpd.www/backend/Session.php on line 79 Warning: session_start(): Session cannot be started after headers have already been sent in /customers/a/5/e/minehubsstudios.com/httpd.www/backend/Session.php on line 79 Warning: Cannot modify header information - headers already sent by (output started at /customers/a/5/e/minehubsstudios.com/httpd.www/backend/auth/RememberMe.php:1) in /customers/a/5/e/minehubsstudios.com/httpd.www/Bootstrap.php on line 161 Warning: Cannot modify header information - headers already sent by (output started at /customers/a/5/e/minehubsstudios.com/httpd.www/backend/auth/RememberMe.php:1) in /customers/a/5/e/minehubsstudios.com/httpd.www/Bootstrap.php on line 162 Warning: Cannot modify header information - headers already sent by (output started at /customers/a/5/e/minehubsstudios.com/httpd.www/backend/auth/RememberMe.php:1) in /customers/a/5/e/minehubsstudios.com/httpd.www/Bootstrap.php on line 163 Warning: Cannot modify header information - headers already sent by (output started at /customers/a/5/e/minehubsstudios.com/httpd.www/backend/auth/RememberMe.php:1) in /customers/a/5/e/minehubsstudios.com/httpd.www/Bootstrap.php on line 164 Blog | Minehubs Studios Skip to content
Minehubs Studios Present GENSTART
  • Media Team

Minehubs Studios Present GENSTART

Copenhagen, June 7, 2024 – We’re thrilled to announce our upcoming short film with the working title GENSTART. The film is developed by Jacob Jørgensen and Alex Persson and written by Jacob Jørgensen. It tells the story of Noah, a young man living in the streets, and Sofia a mechanic with a traumatic past. The two find each other through their shared passion for engines. While Noah struggles to find his place in life and escape his past, Sofia battles the psychological aftermath of a car accide...



Read More




Den Anden Side – Remake!
  • Media Team

Den Anden Side – Remake!

That's right, you read the title correctly. We are remaking Jacob Jørgensen's debut short film, the award-winning: Den Anden Side! About a year ago I got a text from Jacob, asking if I would like to help redoing Den Anden Side, and as this was a no brainer, I got the raw material and went to work. "DAS" (Den Anden Side) is a very special film for most of us who worked on the original. For me, it was the first project I worked on with Minehubs Studios. At first, I applied for the position as mai...



Read More




MineHubs Studios Presents I REGNEN SER JEG DIG
  • Media Team

MineHubs Studios Presents I REGNEN SER JEG DIG

It is with great pleasure that we today can unveil our next film in the line I REGNEN SER JEG DIG, which will be the first film release of the year. The film is based on a psychological love and triangle drama, and will premiere later in 2023. It is written by Christoffer Fischer and Christoffer Jorge Thomsen. In the director's chair you will find Emil G. Mogensen. This will be Emils first film with us out of many.   The Story I REGNEN SER JEG DIG is a film about a tragic breakup between Mal...



Read More




Vi Lyser I Mørket - 4 Stars
  • Media Team

Vi Lyser I Mørket - 4 Stars

2023 has begun and we are back with a new blog post. It is with great pleasure to be able to say that our dear film VI LYSER I MØRKET (WE GLOW IN THE DARK), which was released back in the summer of 2022, started the year by receiving a 4 stars review from Short Films Matter. The film thus scores almost top marks on one of the recognized international independent review sites for short films, which both focuses on upcoming film talents and existing talents on the global short film scene.    ...



Read More