Skip to content

Commit

Permalink
Resolve PHP 5.6 issue. Closes Toxantron#92.
Browse files Browse the repository at this point in the history
  • Loading branch information
Toxantron committed Oct 27, 2018
1 parent 3847a3a commit 9c14ec1
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/controllers/session-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function create()
if ($private)
$token = $this->createHash($data["name"], $data["password"]);
else
$token = $this->createHash($data["name"], bin2hex(random_bytes(8)));
$token = $this->createHash($data["name"], $this->randomKey());
$session->setToken($token);

$session->setLastAction(new DateTime());
Expand All @@ -53,6 +53,16 @@ public function create()
return new NumericResponse($session->getId());
}

// Generate a random key for the public session token
private function randomKey()
{
if (PHP_MAJOR_VERSION >= 7)
$bytes = random_bytes(8);
else
$bytes = openssl_random_pseudo_bytes(8);
return bin2hex($bytes);
}

// Add or remove member
// URL: /api/session/member/{id}/?{mid}
public function member($sessionId, $memberId = 0)
Expand Down

0 comments on commit 9c14ec1

Please sign in to comment.