Generates a random token

@return string
339671
public function generateRandomToken(): string
    {
        $this->token = function_exists('openssl_random_pseudo_bytes') ? openssl_random_pseudo_bytes($this->size) : mcrypt_create_iv($this->size);

        return $this->token;
    }
1102090
protected function create()
    {
        $token = $this->generateTokenString();

        Cache::put($this->getCacheKey(), $token, $this->expire_in);

        return $token;
    }
1346506
protected static function generateSalt(): string
    {
        $result = '';

        static::validateSaltMinLength();

        $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
        $poolSize = strlen($pool);
        for ($i = 0; $i < static::$saltMinLength; $i++) {
            $result .= $pool[rand(0, $poolSize - 1)];
        }

        return $result;
    }
151750
public static function generate_token()
	{
		$token_base = time() . uniqid() . \Config::get('security.token_salt', '') . mt_rand(0, mt_getrandmax());
		if (function_exists('hash_algos') and in_array('sha512', hash_algos()))
		{
			$token = hash('sha512', $token_base);
		}
		else
		{
			$token = md5($token_base);
		}

		return $token;
	}
614856
public function generateCsrfToken() {
		$token = hash("sha512", mt_rand(0, mt_getrandmax()));
		$_SESSION[$this->csrfTokenSessionKey] = $token;
		return $token;
	}
1182961
public static function generateToken()
    {
        // Generate the token based on the current time, plus a random string.
        $token = time() . '.';

        // Start with an empty string.
        $length       = 32;
        $characterset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890';

        // For the desired length, keep adding random characters from the character set.
        for ($i = 0; $i < $length; $i++) {
            $token .= $characterset[mt_rand(0, strlen($characterset) - 1)];
        }

        $sessions = [];

        if (isset($_SESSION['csrftokens'])) {
            $sessions = array_slice($_SESSION['csrftokens'], -50, 50);
        }

        // Add the token to the "token-basket", a place in which we store all the currently valid CSRF tokens.
        $sessions[] = $token;

        $_SESSION['csrftokens'] = $sessions;

        return $token;
    }
1272238
protected function generateToken() {
		$session = $this->getSession();
		if($session->has('_csrf_token'))
			return $session['_csrf_token'];
		else {
			$token = \Asgard\Common\Tools::randstr();
			return $session['_csrf_token'] = $token;
		}
	}
916788
public function _generateUUIDString() {
        return sprintf("%08x%08x%08x%08x",
            $this->_util->randInt32(),
            $this->_util->randInt32(),
            $this->_util->randInt32(),
            $this->_util->randInt32()
        );
    }
31208
public function generateToken()
    {
        if (isset($this->token)) return;

        $this->token = base_convert(md5(uniqid(rand(), true)), 16, 36);
        setcookie($this->getCookieName(), $this->token, time() + $this->cookie_lifetime, '/');
    }
420184
protected String generateToken() {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < TOKEN_MIDDLE_LEN; i++) {
            sb.append(TOKEN_DICT.charAt(random.nextInt(TOKEN_DICT.length())));
        }
        return TOKEN_PREFIX + sb.toString() + TOKEN_SUFFIX;
    }
1220947
function randomToken () {
  return crypto.randomBytes(20).toString('base64').replace(/\//g, '-').replace(/\+/g, '_').replace(/=/g, '');
}
1301783
public static function generateCsrfToken()
  {
    if (version_compare(PHP_VERSION, '7.0.0', '>=')) {
      $_SESSION['csrf_token'] = bin2hex(random_bytes(32));
    } elseif(version_compare(PHP_VERSION, '7.0.0', '<')) {
      if (function_exists('mcrypt_create_iv')) {
        $_SESSION['csrf_token'] = bin2hex(mcrypt_create_iv(32, MCRYPT_DEV_URANDOM));
      } else {
        $_SESSION['csrf_token'] = bin2hex(openssl_random_pseudo_bytes(32));
      }
    }
    return "<input id='csrf_token' type='hidden' name='csrf_token' value='{$_SESSION['csrf_token']}'>";
  }
438427
protected function createTokenId()
    {
        $max = strlen($this->tokenChars) - 1;
        $len = strlen($this->tokenFormat);

        do {
            $out = '';
            for ($i = 0; $i < $len; $i++) {
                if ('\\' == $this->tokenFormat[$i]) {
                    $i++;
                    $out .= $this->tokenFormat[$i];
                } else {
                    $out .= $this->tokenChars[mt_rand(0, $max)];
                }
            }

        } while ($this->db->fetchOne('SELECT gto_id_token FROM gems__tokens WHERE gto_id_token = ?', $out));

        return $out;
    }
180662
protected function generateRandomPassword()
    {
        $alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890+*=-_/()!?[]{}';
        $password = array();
        $alphabetLength = strlen($alphabet) - 1;
        
        for ($i = 0; $i < 10; $i++) {
            $charIndex = mt_rand(0, $alphabetLength);
            $password[] = $alphabet[$charIndex];
        }
        
        $password = implode('', $password);
        
        if (!preg_match('/\d/', $password)) {
            $password = mt_rand(0, 9) . $password . mt_rand(0, 9);
        }
        
        return $password;
    }
264093
public function generate()
    {
        $pickChars = str_repeat(static::DICTIONARY, static::LENGTH);
        for (; ;) {
            $value = substr(str_shuffle($pickChars), 0, static::LENGTH);
            if (preg_match(static::TOKEN_GENERATION_REGEX, $value)) {
                $this->insertQuery->execute([$value]);
                if ($this->insertQuery->rowCount() === 1) {
                    break;
                }
            }
        }

        return $value;
    }
608936
public function generateOneTimeToken(): string
	{
		if(!empty($this->sessionData['mako.tokens']))
		{
			$this->sessionData['mako.tokens'] = array_slice($this->sessionData['mako.tokens'], 0, (static::MAX_TOKENS - 1));
		}
		else
		{
			$this->sessionData['mako.tokens'] = [];
		}

		$token = $this->generateId();

		array_unshift($this->sessionData['mako.tokens'], $token);

		return $token;
	}
1222178
private function generateSalt()
    {
        $str = '';
        $length = 64;
        $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(){}[]/|`,.?+-_=:;<> ';
        $count = strlen($chars);
        
        while ($length--) {
            $str .= $chars[mt_rand(0, $count - 1)];
        }
        
        return 'base64:' . base64_encode($str);
    }