Skip to content

Commit 711efe3

Browse files
committed
Truncate auto-generated usernames to 64 characters
1 parent c0fc912 commit 711efe3

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

app/Services/Subusers/SubuserCreationService.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Pterodactyl\Services\Subusers;
44

5+
use Illuminate\Support\Str;
56
use Pterodactyl\Models\Server;
67
use Pterodactyl\Models\Subuser;
78
use Illuminate\Database\ConnectionInterface;
@@ -84,9 +85,13 @@ public function handle(Server $server, string $email, array $permissions): Subus
8485
throw new ServerSubuserExistsException(trans('exceptions.subusers.subuser_exists'));
8586
}
8687
} catch (RecordNotFoundException $exception) {
88+
// Just cap the username generated at 64 characters at most and then append a random string
89+
// to the end to make it "unique"...
90+
$username = substr(preg_replace('/([^\w\.-]+)/', '', strtok($email, '@')), 0, 64) . Str::random(3);
91+
8792
$user = $this->userCreationService->handle([
8893
'email' => $email,
89-
'username' => preg_replace('/([^\w\.-]+)/', '', strtok($email, '@')) . str_random(3),
94+
'username' => $username,
9095
'name_first' => 'Server',
9196
'name_last' => 'Subuser',
9297
'root_admin' => false,

0 commit comments

Comments
 (0)