From c5a78839df735063babe789964c745850e33d688 Mon Sep 17 00:00:00 2001 From: Uwe Steinmann Date: Thu, 6 Feb 2020 11:32:27 +0100 Subject: [PATCH] add getToken() for generating a random string --- inc/inc.Utils.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/inc/inc.Utils.php b/inc/inc.Utils.php index 52b3102f2..3173c93e4 100644 --- a/inc/inc.Utils.php +++ b/inc/inc.Utils.php @@ -598,6 +598,20 @@ function getBaseUrl() { /* {{{ */ return "http".((isset($_SERVER['HTTPS']) && (strcmp($_SERVER['HTTPS'],'off')!=0)) ? "s" : "")."://".$_SERVER['HTTP_HOST']; } /* }}} */ +function getToken($length){ + $token = ""; + $codeAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + $codeAlphabet.= "abcdefghijklmnopqrstuvwxyz"; + $codeAlphabet.= "0123456789"; + $max = strlen($codeAlphabet); + + for ($i=0; $i < $length; $i++) { + $token .= $codeAlphabet[random_int(0, $max-1)]; + } + + return $token; +} + class SeedDMS_CSRF { protected $secret;