Truncate auto-generated usernames to 64 characters

This commit is contained in:
Dane Everitt 2020-09-24 19:37:39 -07:00
parent c0fc9125ed
commit 711efe34bb
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53

View file

@ -2,6 +2,7 @@
namespace Pterodactyl\Services\Subusers;
use Illuminate\Support\Str;
use Pterodactyl\Models\Server;
use Pterodactyl\Models\Subuser;
use Illuminate\Database\ConnectionInterface;
@ -84,9 +85,13 @@ class SubuserCreationService
throw new ServerSubuserExistsException(trans('exceptions.subusers.subuser_exists'));
}
} catch (RecordNotFoundException $exception) {
// Just cap the username generated at 64 characters at most and then append a random string
// to the end to make it "unique"...
$username = substr(preg_replace('/([^\w\.-]+)/', '', strtok($email, '@')), 0, 64) . Str::random(3);
$user = $this->userCreationService->handle([
'email' => $email,
'username' => preg_replace('/([^\w\.-]+)/', '', strtok($email, '@')) . str_random(3),
'username' => $username,
'name_first' => 'Server',
'name_last' => 'Subuser',
'root_admin' => false,