Update random ID method to use str_random and not random_bytes

The use of random_bytes in combination with bin2hex was producing a lot of duplicate keys when tested in batches of 10k (anywhere from 2 to 6). The use of str_random yielded no duplicates even at scales of 100k keys that were 8 characters.
This commit is contained in:
Dane Everitt 2017-09-13 23:07:02 -05:00
parent 0e518be6ca
commit a8c4d6afdb
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
14 changed files with 50 additions and 59 deletions

View file

@ -28,7 +28,7 @@ use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
class NodeCreationService
{
const DAEMON_SECRET_LENGTH = 18;
const DAEMON_SECRET_LENGTH = 36;
/**
* @var \Pterodactyl\Contracts\Repository\NodeRepositoryInterface
@ -55,7 +55,7 @@ class NodeCreationService
*/
public function handle(array $data)
{
$data['daemonSecret'] = bin2hex(random_bytes(self::DAEMON_SECRET_LENGTH));
$data['daemonSecret'] = str_random(self::DAEMON_SECRET_LENGTH);
return $this->repository->create($data);
}

View file

@ -83,7 +83,7 @@ class NodeUpdateService
}
if (! is_null(array_get($data, 'reset_secret'))) {
$data['daemonSecret'] = bin2hex(random_bytes(NodeCreationService::DAEMON_SECRET_LENGTH));
$data['daemonSecret'] = str_random(NodeCreationService::DAEMON_SECRET_LENGTH);
unset($data['reset_secret']);
}