Viewing File: /usr/local/cpanel/3rdparty/wpinstaller/src/WpInstaller/StringGenerator.php

<?php
namespace WpInstaller;

class StringGenerator {
    const DEFAULT_PASSWORD_LENGTH = 17;

    public static function gen_password($length = self::DEFAULT_PASSWORD_LENGTH) {
        return self::random_string($length, true);
    }

    public static function random_string($length, $special_chars=false) {
        $character_pool = array_merge(
            range(0, 9),
            range('a', 'z'),
            range('A', 'Z'),
            ($special_chars ? str_split('!@#$%^&*:./?=-_[]{}()<>') : [])
        );

        $character_pool = implode($character_pool);
        $max_key = mb_strlen($character_pool, '8bit') - 1;

        $str = '';
        while (strlen($str) < $length) {
            // Generates cryptographically secure pseudo-random integers
            $str .= $character_pool[random_int(0, $max_key)];
        }

        return $str;
    }
}

?>

Back to Directory File Manager