From c4cbffd9eae85d9f2aef509101364f6a6895d6e8 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Sat, 30 Dec 2017 13:41:34 -0600 Subject: [PATCH] Fix API key substr --- app/Facades/Utils.php | 2 +- tests/UtilsTest.php | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/app/Facades/Utils.php b/app/Facades/Utils.php index 2fe0eb31..d1892c25 100644 --- a/app/Facades/Utils.php +++ b/app/Facades/Utils.php @@ -17,7 +17,7 @@ class Utils extends Facade */ public static function generateApiKey() { - $key = substr(0, 12, sha1(time() . mt_rand())); + $key = substr(sha1(time() . mt_rand()), 0, 12); return $key; } diff --git a/tests/UtilsTest.php b/tests/UtilsTest.php index 7969ef47..c1ed7823 100644 --- a/tests/UtilsTest.php +++ b/tests/UtilsTest.php @@ -51,4 +51,10 @@ class UtilsTest extends TestCase $t = Utils::minutesToTimeString(43200); $this->assertEquals('720h 0m', $t); } + + public function testApiKey() + { + $api_key = Utils::generateApiKey(); + $this->assertNotNull($api_key); + } }