33 lines
869 B
PHP
33 lines
869 B
PHP
<?php
|
|
namespace Cjel\TemplatesAide\Utility;
|
|
|
|
/***
|
|
*
|
|
* This file is part of the "" Extension for TYPO3 CMS.
|
|
*
|
|
* For the full copyright and license information, please read the
|
|
* LICENSE.txt file that was distributed with this source code.
|
|
*
|
|
* (c) 2019 Philipp Dieter <philipp@glanzstueck.agency>, Glanzstück GmbH
|
|
*
|
|
***/
|
|
|
|
class RandomStringUtility
|
|
{
|
|
public static function getToken(
|
|
int $length = 64,
|
|
string $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
|
|
): string {
|
|
if ($length < 1) {
|
|
throw new \RangeException("Length must be a positive integer");
|
|
}
|
|
$pieces = [];
|
|
$max = mb_strlen($keyspace, '8bit') - 1;
|
|
for ($i = 0; $i < $length; ++$i) {
|
|
$pieces []= $keyspace[random_int(0, $max)];
|
|
}
|
|
return implode('', $pieces);
|
|
}
|
|
|
|
}
|