PHPMailer\PHPMailer
PHPMailer::generateId
Create a unique ID to use for boundaries.
Method of the class: PHPMailer{}
No Hooks.
Returns
String.
Usage
// protected - for code of main (parent) or child class $result = $this->generateId();
PHPMailer::generateId() PHPMailer::generateId code WP 7.0.1
protected function generateId()
{
$len = 32; //32 bytes = 256 bits
$bytes = '';
if (function_exists('random_bytes')) {
try {
// phpcs:ignore PHPCompatibility.FunctionUse.NewFunctions.random_bytesFound -- Wrapped in function_exists.
$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)));
}