From e91dfdbc7549b60a6bc2decff885a26f7fbb365f Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Thu, 9 Apr 2020 00:36:37 +0200 Subject: remember me with hash comparaison close #68 --- app/class/Modelauthtoken.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'app/class/Modelauthtoken.php') diff --git a/app/class/Modelauthtoken.php b/app/class/Modelauthtoken.php index 0a55e64..18ef6a7 100644 --- a/app/class/Modelauthtoken.php +++ b/app/class/Modelauthtoken.php @@ -8,7 +8,7 @@ class Modelauthtoken extends Modeldb { const AUTHTOKEN_REPO_NAME = 'authtoken'; - + const AUTHTOKEN_ID_LENGTH = 30; public function __construct() { @@ -29,6 +29,14 @@ class Modelauthtoken extends Modeldb 'creationdate' => '1' ]; $tokendata = new Document($datas); + + $exist = true; + while ($exist !== false) { + $id = bin2hex(random_bytes(self::AUTHTOKEN_ID_LENGTH)); + $exist = $this->repo->findById($id); + } + + $tokendata->setId($id); return $this->repo->store($tokendata); } -- cgit v1.2.3