for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Yokai\SecurityTokenBundle\Generator;
use LogicException;
/**
* This token generator is using `openssl` extension to generate random token values.
*
* @author Yann Eugoné <[email protected]>
*/
class OpenSslTokenGenerator implements TokenGeneratorInterface
{
const DEFAULT_LENGTH = 32;
* @var int
private $length;
* @param int $length Token length
public function __construct($length = self::DEFAULT_LENGTH)
if (!function_exists('openssl_random_pseudo_bytes')) {
throw new LogicException('The extension "openssl" is required to use "open ssl" token generator.');
}
$this->length = $length;
* @inheritdoc
public function generate()
return rtrim(strtr(base64_encode(openssl_random_pseudo_bytes($this->length)), '+/', '-_'), '=');