PHPMailer\PHPMailer

PHPMailer::generateId()protectedWP 1.0

Create a unique ID to use for boundaries.

Method of the class: PHPMailer{}

No Hooks.

Return

String.

Usage

// protected - for code of main (parent) or child class
$result = $this->generateId();

PHPMailer::generateId() code WP 6.4.3

protected function generateId()
{
    $len = 32; //32 bytes = 256 bits
    $bytes = '';
    if (function_exists('random_bytes')) {
        try {
            $bytes = random_bytes($len);
        } catch (\Exception $e) {
            //Do nothing
        }
    } elseif (function_exists('openssl_random_pseudo_bytes')) {
        /** @noinspection CryptographicallySecureRandomnessInspection */
        $bytes = openssl_random_pseudo_bytes($len);
    }
    if ($bytes === '') {
        //We failed to produce a proper random string, so make do.
        //Use a hash to force the length to the same as the other methods
        $bytes = hash('sha256', uniqid((string) mt_rand(), true), true);
    }

    //We don't care about messing up base64 format here, just want a random string
    return str_replace(['=', '+', '/'], '', base64_encode(hash('sha256', $bytes, true)));
}