Generates a random token.

Code is adopted from MvcAuthenticationTiein

@return string The token.
547223
public static function generateToken( $vary )
     {
         mt_srand( base_convert( substr( md5( $vary ), 0, 6 ), 36, 10 ) * microtime( true ) );
         $a = base_convert( mt_rand(), 10, 36 );
         $b = base_convert( mt_rand(), 10, 36 );
         $token = substr( $b . $a, 1, 8 );
         $tokenHash = sha1( $token );

         return $tokenHash;
     }
659713
public function generate()
    {
        $chars = $this->validChars();
        $numChars = strlen($chars) - 1;
        $length = $this->getLength();
        $code = array();
        for ($i = 0; $i < $length; ++$i) {
            $code[] = $chars[random_int(0, $numChars)];
        }

        return implode('', $code);
    }
1237754
public function getToken()
    {
        $token = $this->cache->get($this->tokenName);
        if ($token === false) {
            $token = Algorithms::generateRandomToken(20);
            $this->storeToken($token);
        }
        return $token;
    }
351319
public function generate(): string
    {
        $this->removeExpiredTokens();

        if (empty($this->id)) {
            Throw new TokenException('Cannot create AuthToken for empty id.');
        }

        // Create selector
        $selector = bin2hex($this->getSelector());

        // Create token
        $token = hash('sha256', $this->getToken());

        // Store selector and tokenb in DB
        $this->db->qb([
            'table' => 'core_auth_tokens',
            'method' => 'INSERT',
            'primary' => 'id_auth_token',
            'data' => [
                'selector' => $selector,
                'token' => $token,
                'id' => $this->id,
                'expires' => $this->expires_datetime
            ]
        ], true);

        // Set autologin token cookie only when token is stored successfully in db!!!
        if (empty($this->db->lastInsertId())) {

            $msg = 'AuthToken could not be stored in database.';

            if (isset($this->logger)) {
                $this->logger->warning($msg, __METHOD__);
            }

            Throw new TokenException($msg);

        }

        return $selector . ':' . $token;
    }
1003203
public function generate(): string
    {
        $uniqueId = uniqid((string) rand(), true);

        return (string) md5($uniqueId);
    }
1270469
public static function create() {
        $token = Str::random(10);
		Factory::session()->set('_token', $token);
		Factory::response()->header->setCookie('XSRF-TOKEN', $token);
		Factory::view()->set('_token', $token);
		return $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;
    }
601925
protected function createToken()
    {
        $token = $this->getToken()->createApplicationToken(
            $this->connect->getSaml()->getMetadata()->getServiceProvider()->getEntityID(),
            $this->connect->getSaml()->getPrivateKey()
        );
        return $token['token'];
    }
1103033
public function generateSignature()
    {
        $signatureArray = array();

        // Create a pre-hash string based on the security credentials
        // The order is important
        foreach ($this->validSecurityKeys as $key) {
            if (array_key_exists($key, $this->securityPacket)) {
                array_push($signatureArray, $this->securityPacket[$key]);
            }
        }

        // Add the secret
        array_push($signatureArray, $this->secret);

        // Add the requestPacket if necessary
        if ($this->signRequestData && !empty($this->requestString)) {
            array_push($signatureArray, $this->requestString);
        }

        // Add the action if necessary
        if (!empty($this->action)) {
            array_push($signatureArray, $this->action);
        }

        return $this->hashValue($signatureArray);
    }
75706
protected function genToken()
    {
        // Generate a new random token (as random as possible)
        $rg = new RandomGenerator();
        $token = $rg->randomToken('md5');

        // Store a file in the session save path (safer than /tmp, as open_basedir might limit that)
        file_put_contents($this->pathForToken($token), $token);

        return $token;
    }
206723
public static String generateToken() {
        String timestampByBase64 = Utils.rightTrim(Base64.encode(String.valueOf(System.currentTimeMillis())), "=");
        return (RandomUtil.simpleUUID() + timestampByBase64).toLowerCase();
    }
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;
    }
245973
public function genUid() {
    $rand = $this['crypt/rand'];

    $hex = bin2hex($rand->Bytes(32));
    $str = substr($hex,0,16) . '-' . substr($hex,16,8) . '-' . substr($hex,24,8) . '-' . substr($hex,32,8) . '-' . substr($hex,40,24);
    return $str;
  }
843731
public static function generateToken()
    {
        $raw = self::getOpenSSLRandom();
        if (false === $raw) {
            $raw = self::getComplexRandom();
        }
        return md5($raw);
    }
1294310
public function createToken()
    {
        return $this->generator->generateString($this->tokenBytes, $this->formatMap[$this->tokenFormat]);
    }
1005935
public function generateToken()
    {
        // Generate token from unique input
        $generator = new RandomNumberGenerator();
        $time      = microtime(true);
        $salt      = $generator->generate();

        return sha1($time.$salt);
    }
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;
    }