新 order_id 生成，32位内.

@param $salt integer

@return string

@farwish
320914
public static function orderid($salt = '')
    {
        // 14 + 8 + 5 + 3 = 30
        return str_replace('.', '', microtime(true)) . 
            date('Ymd') .
            str_pad(substr($salt, 0, 3), 5, 0) . 
            mt_rand(100, 999);
    }
599408
protected function createSalt()
    {
        $pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ./';
        $max = strlen($pool) - 1;
        $salt = '';
        for ($i = 0; $i < $this->saltLength; ++$i) {
            $salt .= $pool[random_int(0, $max)];
        }
        return $salt;
    }
651135
public function regenerateId(bool $keepOld = false): string
	{
		// Delete old data if we don't want to keep it

		if(!$keepOld)
		{
			$this->store->delete($this->sessionId);
		}

		// Generate a new id and set a new cookie

		$this->sessionId = $this->generateId();

		$this->setCookie();

		// Return the new session id

		return $this->sessionId;
	}
822627
public static String generateSalt(int saltLength) {
		StringBuilder salt = new StringBuilder(saltLength);
		for (int i=0; i<saltLength; i++) {
			salt.append(CHAR_ARRAY[random.nextInt(CHAR_ARRAY.length)]);
		}
		return salt.toString();
	}
647790
public function crypt($salt = null)
    {
        $this->setInternalValue(crypt($this->getInternalValue(), $salt));

        return $this;
    }
854387
private function createId($time = null)
    {
        $pid = getmypid();
        $inc = $this->readInc($pid);

        $id = $this->intToMaxLengthHex(null !== $time ? (int) $time : time(), 8);
        $id .= $this->intToMaxLengthHex(crc32(self::getHostname()), 6);
        $id .= $this->intToMaxLengthHex($pid, 4);
        $id .= $this->intToMaxLengthHex($inc, 6);

        return $id;
    }
664472
public static function genOrderid($prefix = 'YK')
    {
        $uniq = uniqid(TRUE);

        return $prefix . date('Ymd') . $uniq . str_shuffle($uniq);
    }
374329
public function getAddIndexDDL(Index $index)
    {
        // don't create index form primary key
        if ($this->getPrimaryKeyName($index->getTable()) == $this->quoteIdentifier($index->getName())) {
            return "";
        }

        $pattern = "
CREATE %sINDEX %s ON %s (%s)%s;
";

        return sprintf($pattern,
            $index->getIsUnique() ? 'UNIQUE ' : '',
            $this->quoteIdentifier($index->getName()),
            $this->quoteIdentifier($index->getTable()->getName()),
            $this->getColumnListDDL($index->getColumns()),
            $this->generateBlockStorage($index)
        );
    }
1009257
public static function hash($str, $salt = '', $plain = false)
    {
        $size = 512;
        $rounds = 1;
        if (strncmp($salt, '$', 1) === 0) {
            $e = explode('$', $salt, 3);
            $ee = explode('=', $e[1]);
            if (ctype_digit($ee[0])) {
                $size = (int)$e[1];
            }
            if (isset($ee[1]) && ctype_digit($e[1])) {
                $size = (int)$e[1];
            }
        }
        $hash = $str . $salt;
        if ($rounds < 1) {
            $rounds = 1;
        } elseif ($rounds > 128) {
            $rounds = 128;
        }
        for ($i = 0; $i < $rounds; ++$i) {
            $hash = \keccak_hash($hash, $size);
        }
        if ($plain) {
            return $hash;
        }
        return base64_encode($hash);
    }
1302921
protected function shuffle($alphabet, $salt): string
    {
        $key = $alphabet.' '.$salt;

        if (isset($this->shuffledAlphabets[$key])) {
            return $this->shuffledAlphabets[$key];
        }

        $saltLength = \mb_strlen($salt);
        $saltArray = $this->multiByteSplit($salt);
        if (!$saltLength) {
            return $alphabet;
        }
        $alphabetArray = $this->multiByteSplit($alphabet);
        for ($i = \mb_strlen($alphabet) - 1, $v = 0, $p = 0; $i > 0; $i--, $v++) {
            $v %= $saltLength;
            $p += $int = \mb_ord($saltArray[$v], 'UTF-8');
            $j = ($int + $v + $p) % $i;

            $temp = $alphabetArray[$j];
            $alphabetArray[$j] = $alphabetArray[$i];
            $alphabetArray[$i] = $temp;
        }
        $alphabet = \implode('', $alphabetArray);
        $this->shuffledAlphabets[$key] = $alphabet;

        return $alphabet;
    }
1089879
public static function getUserIdSalt()
    {
        $salt = Option::get(self::OPTION_USERID_SALT);
        if (empty($salt)) {
            $salt = Common::getRandomString($len = 40, $alphabet = "abcdefghijklmnoprstuvwxyzABCDEFGHIJKLMNOPRSTUVWXYZ0123456789_-$");
            Option::set(self::OPTION_USERID_SALT, $salt, 1);
        }
        return $salt;
    }
634449
public function salt(int $length = 32): string {
    try {
      return random_bytes($length);
    } catch(Exception $e) {
      throw new RuntimeException('Could not generate crytographically secure salt', 0, $e);
    }
  }
1304763
public static function generateId()
    {
        static $inc = 0;

        $ts = pack('N', time());
        $m = substr(md5(gethostname()), 0, 3);
        $pid = pack('n', 1);
        $trail = substr(pack('N', $inc++), 1, 3);

        $bin = sprintf('%s%s%s%s', $ts, $m, $pid, $trail);
        $id = '';
        for ($i = 0; $i < 12; $i++) {
            $id .= sprintf('%02X', ord($bin[$i]));
        }

        return strtolower($id);
    }
488001
private function hi($str, $salt, $i)
    {
        $int1 = "\0\0\0\1";
        $ui = call_user_func($this->hmac, $str, $salt . $int1, true);
        $result = $ui;
        for ($k = 1; $k < $i; $k++)
        {
            $ui = call_user_func($this->hmac, $str, $ui, true);
            $result = $result ^ $ui;
        }
        return $result;
    }
897367
public static function hash($string)
    {
        $salt = self::createSalt();
        return self::PREFIX.$salt.'$'.self::createSubHash($string, $salt);
    }
765267
protected function shuffle($alphabet, $salt)
    {
        $saltLength = strlen($salt);

        if (!$saltLength) {
            return $alphabet;
        }

        for ($i = strlen($alphabet) - 1, $v = 0, $p = 0; $i > 0; $i--, $v++) {
            $v %= $saltLength;
            $p += $int = ord($salt[$v]);
            $j = ($int + $v + $p) % $i;

            $temp = $alphabet[$j];
            $alphabet[$j] = $alphabet[$i];
            $alphabet[$i] = $temp;
        }

        return $alphabet;
    }
104113
public function create($password)
    {
        if (!$this->salt) {
            $salt = str_replace('+', '.', base64_encode(CryptHelper::genRandomBytes(64)));
        } else {
            $salt = $this->salt;
        }

        switch ($this->type) {
            case static::MD5:
                $salt = '$1$' . $salt . '$';
                break;

            case static::SHA256:
                $cost = CryptHelper::limitInteger($this->cost, 1000);

                $salt = '$5$rounds=' . $cost . '$' . $salt . '$';
                break;

            case static::SHA512:
                $cost = CryptHelper::limitInteger($this->cost, 1000);

                $salt = '$6$rounds=' . $cost . '$' . $salt . '$';
                break;

            case static::SODIUM_ARGON2:
                return \Sodium\crypto_pwhash_str(
                    $password,
                    \Sodium\CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE,
                    \Sodium\CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE
                );

            case static::SODIUM_SCRYPT:
                return \Sodium\crypto_pwhash_scryptsalsa208sha256_str(
                    $password,
                    \Sodium\CRYPTO_PWHASH_SCRYPTSALSA208SHA256_OPSLIMIT_INTERACTIVE,
                    \Sodium\CRYPTO_PWHASH_SCRYPTSALSA208SHA256_MEMLIMIT_INTERACTIVE
                );

            default:
            case static::BLOWFISH:
                $salt = CryptHelper::repeatToLength($salt, 22, true);
                $cost = CryptHelper::limitInteger($this->cost, 4, 31);

                $options['cost'] = $cost;

                return password_hash($password, PASSWORD_BCRYPT, $options);
                break;
        }

        if (!function_exists('crypt')) {
            throw new \RangeException("crypt() must be loaded for Password::create method");
        }

        return crypt($password, $salt);
    }