From d005534c165ceb053dfbbaff177f680ddaf2e845 Mon Sep 17 00:00:00 2001 From: rsgrinko Date: Wed, 22 Dec 2021 16:56:33 +0300 Subject: [PATCH] =?UTF-8?q?[+]=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D1=8B=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B=20=D1=81=20=D1=82=D0=BE?= =?UTF-8?q?=D0=BA=D0=B5=D0=BD=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/lib/CUser.class.php | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/inc/lib/CUser.class.php b/inc/lib/CUser.class.php index a935381..71ad983 100644 --- a/inc/lib/CUser.class.php +++ b/inc/lib/CUser.class.php @@ -97,17 +97,21 @@ class CUser { /** * Создание пользовательского токена */ - /*public static function createUserToken($userId):string { - - - self::$DB->update(self::$table, array('id' => $result['id']), array('last_active' => time())); + public static function createUserToken($userId):string { + $newToken = self::generateGUID(); + self::$DB->update(self::$table, array('id' => $userId), array('token' => $newToken)); - if($result) { - return $result['token']; - } else { - return ''; - } - }*/ + return $newToken; + } + + /** + * Генерация GUID + */ + private static function generateGUID():string { + $uid = dechex( microtime(true) * 1000 ) . bin2hex( random_bytes(8) ); + $guid = vsprintf('RG%s-1000-%s-8%.3s-%s%s%s0', str_split($uid,4)); + return strtoupper($guid); + } /** * Проверка пользователя на онлайн