Generates a random token and checks for uniqueness

@return string A non-existing 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;
    }
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, '/');
    }
727890
private function _generateUniqueId()
    {
        $rand = uniqid(rand(10, 99));
        $time = microtime(true);
        $micro = sprintf('%06d', ($time - floor($time)) * 1000000);
        $date = new DateTime(date('Y-m-d H:i:s.' . $micro, $time));
        return sha1($date->format('YmdHisu'));
    }
464873
public function generateToken()
    {
        do {
            $token = sha1(microtime());
        } while ($this->newQuery()->where(['token' => $token])->count() > 0);

        return $token;
    }
722996
protected function generateToken()
	{
		if (function_exists('openssl_random_pseudo_bytes'))
		{
			$token = base64_encode( openssl_random_pseudo_bytes(32));
		}
		elseif (function_exists("hash_algos") and in_array("sha256",hash_algos()))
		{
			// generate a random token using sha256
			$token = hash("sha256",mt_rand(0,mt_getrandmax()));
		}
		else
		{
			// use a randomizer algorithm if we don't have hash-sha256 available
			$token='';
			for ($i=0;$i<64;++$i)
			{
				$r=mt_rand(0,35);
				$token .= $r<26 ? chr(ord('a')+$r) : chr(ord('0')+$r-26);
			}
		}

		return $token;
	}
329200
protected function generateToken()
    {
        if ($this->token === null) {
            $secret = array(
                'install' => __DIR__,
                'name' => $this->name,
            );

            if (isset($_SESSION)) {
                $key = sha1(__DIR__ . '/' . 'formidable_secret');

                if (isset($_SESSION[$key])) {
                    $secret['csrf'] = $_SESSION[$key];
                } else {
                    $csrf = sha1(uniqid(mt_rand(), true).'|'.gettimeofday(true));
                    $_SESSION[$key] = $csrf;
                    $secret['csrf'] = $csrf;
                }
            }

            $this->token = sha1(serialize($secret));
        }
    }
944005
public function getNewToken()
    {
        $post = array(
            'auth' => array(
                'username' => $this->username,
                'password' => $this->password,
            ),
        );
        return $this->http->call(HttpMethod::POST, $this->host.'/auth', $post)->token;
    }
1230908
private function generateUuid()
    {
        if (!function_exists('openssl_random_pseudo_bytes')) {
            $this->requestId = uniqid('unq', true);
        } else {
            $data = openssl_random_pseudo_bytes(16);
            // set version to 0100
            $data[6] = chr(ord($data[6]) & 0x0f | 0x40);
            // set bits 6-7 to 10
            $data[8] = chr(ord($data[8]) & 0x3f | 0x80);
            $this->requestId = vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
        }

        return $this->requestId;
    }
34382
private function generateActivationToken(): string
    {
        $this->setSize(32);
        $this->generateRandomToken();

        $this->activation_token = hash('sha256', $this->token);

        return $this->activation_token;
    }
916788
public function _generateUUIDString() {
        return sprintf("%08x%08x%08x%08x",
            $this->_util->randInt32(),
            $this->_util->randInt32(),
            $this->_util->randInt32(),
            $this->_util->randInt32()
        );
    }
864183
public function generateToken()
    {
        $token   = md5(__CLASS__.uniqid());

        $sesCont = new SessionContainer(self::SESSION_KEY);
        $sesCont->$token = time();
        $sesCont->setExpirationSeconds(30, $token);

        return $token;
    }
697128
private function generateToken()
    {
        return Hash::hash256(self::getHa1()->getHash(), $this->getNonce(), $this->getRounds());
    }
976226
protected function generateRandomString()
    {
        if (!extension_loaded('openssl')) {
            throw new \Exception('The OpenSSL PHP extension is required.');
        }

        $length = 32;
        $bytes = openssl_random_pseudo_bytes($length);

        return strtr(substr(base64_encode($bytes), 0, $length), '+/=', '_-.');
    }
358994
public function generateToken()
    {
        $adminUser = $this->auth->getUser();
        $refreshToken = $adminUser->getRefreshToken();

        if ($refreshToken) {
            $accessToken = $this->client->getAccessToken(
                $this->configFactory->getTokenUrl(),
                $this->buildUrlParams(
                    $this->helper->encryptor->decrypt($refreshToken)
                )
            );

            if (is_string($accessToken)) {
                return $accessToken;
            }
        }

        return false;
    }
628728
public function getRandomPassword()
    {
        $salt = "abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ0123456789";
        $pass = "";

        srand((double)microtime()*1000000);

        $i = 0;

        while ($i <= 7)
        {
            $num = rand() % strlen($salt);
            $tmp = substr($salt, $num, 1);
            $pass = $pass . $tmp;
            $i++;
        }

        return $pass;
    }
997029
private static function unique_key() {
		if ( ! function_exists( 'random_int' ) ) {
			throw new Exception( "'random_int' does not exist" );
		}

		$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-_ []{}<>~`+=,.;:/?|';
		$key   = '';

		for ( $i = 0; $i < 64; $i++ ) {
			// phpcs:ignore PHPCompatibility.FunctionUse.NewFunctions.random_intFound -- Will be called only if function exists.
			$key .= substr( $chars, random_int( 0, strlen( $chars ) - 1 ), 1 );
		}

		return $key;
	}
56344
protected function generateToken()
    {
        if (function_exists('openssl_random_pseudo_bytes')) {
            return bin2hex(openssl_random_pseudo_bytes(16));
        }

        return sprintf("%04x", mt_rand(0, 0xFFFF))
            . sprintf("%04x", mt_rand(0, 0xFFFF))
            . sprintf("%04x", mt_rand(0, 0xFFFF))
            . sprintf("%04x", mt_rand(0, 0xFFFF));
    }