From 5611cf49533b34ea1ef0aa21580fd910562d5490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jir=CC=8Ci=CC=81=20Svoboda?= Date: Fri, 5 Jun 2015 01:00:43 +0200 Subject: [PATCH] fixes --- src/components/AuthMeToken.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/components/AuthMeToken.php b/src/components/AuthMeToken.php index 73e87e3..cc030ce 100644 --- a/src/components/AuthMeToken.php +++ b/src/components/AuthMeToken.php @@ -10,7 +10,7 @@ class AuthMeToken { /** * Hash template */ - const HASH_TEMPLATE = '%s-%s-%s'; + const TOKEN_TEMPLATE = '%s-%s-%s'; /** * @var int expiry time @@ -71,7 +71,7 @@ public function getSecondaryKey() */ public function asString($secret) { - $source = sprintf(self::HASH_TEMPLATE, $this->_primaryKey, $this->_secondaryKey, $this->_timestamp); + $source = sprintf(self::TOKEN_TEMPLATE, $this->_primaryKey, $this->_secondaryKey, $this->_timestamp); return $this->_encrypt($source, $secret); } @@ -116,11 +116,9 @@ public static function initFromString($string, $secret) { $decrypted = self::_decrypt($string, $secret); - $parts = explode('-', $decrypted); - - if (count($parts) == 3) + if (preg_match('/^(\d+)\-(.*)\-(\d+)$/', $decrypted, $matches)) { - return new self($parts[0], $parts[1], $parts[2]); + return new self($matches[1], $matches[2], $matches[3]); } return null;