mirror of
				https://github.com/pelican-dev/panel.git
				synced 2025-10-31 05:46:51 +01:00 
			
		
		
		
	Replace str_random with Str::random (#1676)
				
					
				
			Co-authored-by: RMartinOscar <40749467+RMartinOscar@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									925ab26fb4
								
							
						
					
					
						commit
						420730ba1f
					
				| @ -10,6 +10,7 @@ use Filament\Actions\Action; | ||||
| use Filament\Actions\ActionGroup; | ||||
| use Filament\Resources\Pages\CreateRecord; | ||||
| use Illuminate\Database\Eloquent\Model; | ||||
| use Illuminate\Support\Str; | ||||
| 
 | ||||
| class CreateApiKey extends CreateRecord | ||||
| { | ||||
| @ -36,7 +37,7 @@ class CreateApiKey extends CreateRecord | ||||
|     protected function handleRecordCreation(array $data): Model | ||||
|     { | ||||
|         $data['identifier'] = ApiKey::generateTokenIdentifier(ApiKey::TYPE_APPLICATION); | ||||
|         $data['token'] = str_random(ApiKey::KEY_LENGTH); | ||||
|         $data['token'] = Str::random(ApiKey::KEY_LENGTH); | ||||
|         $data['user_id'] = auth()->user()->id; | ||||
|         $data['key_type'] = ApiKey::TYPE_APPLICATION; | ||||
| 
 | ||||
|  | ||||
| @ -17,6 +17,7 @@ use Filament\Forms\Components\Select; | ||||
| use Filament\Forms\Components\TextInput; | ||||
| use Filament\Resources\Pages\ListRecords; | ||||
| use Filament\Support\Enums\IconSize; | ||||
| use Illuminate\Support\Str; | ||||
| 
 | ||||
| class ListDatabases extends ListRecords | ||||
| { | ||||
| @ -63,7 +64,7 @@ class ListDatabases extends ListRecords | ||||
|                 ]) | ||||
|                 ->action(function ($data, DatabaseManagementService $service) use ($server) { | ||||
|                     if (empty($data['database'])) { | ||||
|                         $data['database'] = str_random(12); | ||||
|                         $data['database'] = Str::random(12); | ||||
|                     } | ||||
|                     $data['database'] = 's'. $server->id . '_' . $data['database']; | ||||
| 
 | ||||
|  | ||||
| @ -4,6 +4,7 @@ namespace App\Helpers; | ||||
| 
 | ||||
| use Carbon\Carbon; | ||||
| use Cron\CronExpression; | ||||
| use Illuminate\Support\Str; | ||||
| use Illuminate\Support\ViewErrorBag; | ||||
| 
 | ||||
| class Utilities | ||||
| @ -14,7 +15,7 @@ class Utilities | ||||
|      */ | ||||
|     public static function randomStringWithSpecialCharacters(int $length = 16): string | ||||
|     { | ||||
|         $string = str_random($length); | ||||
|         $string = Str::random($length); | ||||
|         // Given a random string of characters, randomly loop through the characters and replace some
 | ||||
|         // with special characters to avoid issues with MySQL password requirements on some servers.
 | ||||
|         try { | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| namespace App\Services\Api; | ||||
| 
 | ||||
| use App\Models\ApiKey; | ||||
| use Illuminate\Support\Str; | ||||
| 
 | ||||
| class KeyCreationService | ||||
| { | ||||
| @ -33,7 +34,7 @@ class KeyCreationService | ||||
|         $data = array_merge($data, [ | ||||
|             'key_type' => $this->keyType, | ||||
|             'identifier' => ApiKey::generateTokenIdentifier($this->keyType), | ||||
|             'token' => str_random(ApiKey::KEY_LENGTH), | ||||
|             'token' => Str::random(ApiKey::KEY_LENGTH), | ||||
|         ]); | ||||
| 
 | ||||
|         if ($this->keyType !== ApiKey::TYPE_APPLICATION) { | ||||
|  | ||||
| @ -10,6 +10,7 @@ use Illuminate\Database\ConnectionInterface; | ||||
| use App\Exceptions\Repository\DuplicateDatabaseNameException; | ||||
| use App\Exceptions\Service\Database\TooManyDatabasesException; | ||||
| use App\Exceptions\Service\Database\DatabaseClientFeatureNotEnabledException; | ||||
| use Illuminate\Support\Str; | ||||
| 
 | ||||
| class DatabaseManagementService | ||||
| { | ||||
| @ -85,7 +86,7 @@ class DatabaseManagementService | ||||
| 
 | ||||
|         $data = array_merge($data, [ | ||||
|             'server_id' => $server->id, | ||||
|             'username' => sprintf('u%d_%s', $server->id, str_random(10)), | ||||
|             'username' => sprintf('u%d_%s', $server->id, Str::random(10)), | ||||
|             'password' => Utilities::randomStringWithSpecialCharacters(24), | ||||
|         ]); | ||||
| 
 | ||||
|  | ||||
| @ -3,6 +3,7 @@ | ||||
| namespace App\Services\Users; | ||||
| 
 | ||||
| use App\Models\User; | ||||
| use Illuminate\Support\Str; | ||||
| use PragmaRX\Google2FA\Google2FA; | ||||
| use Illuminate\Database\ConnectionInterface; | ||||
| use App\Exceptions\Service\User\TwoFactorAuthenticationTokenInvalid; | ||||
| @ -48,7 +49,7 @@ class ToggleTwoFactorService | ||||
|             if ((!$toggleState && !$user->use_totp) || $toggleState) { | ||||
|                 $user->recoveryTokens()->delete(); | ||||
|                 for ($i = 0; $i < 10; $i++) { | ||||
|                     $token = str_random(10); | ||||
|                     $token = Str::random(10); | ||||
|                     $user->recoveryTokens()->forceCreate([ | ||||
|                         'token' => password_hash($token, PASSWORD_DEFAULT), | ||||
|                     ]); | ||||
|  | ||||
| @ -37,7 +37,7 @@ class UserCreationService | ||||
|         $this->connection->beginTransaction(); | ||||
|         if (empty($data['password'])) { | ||||
|             $generateResetToken = true; | ||||
|             $data['password'] = $this->hasher->make(str_random(30)); | ||||
|             $data['password'] = $this->hasher->make(Str::random(30)); | ||||
|         } | ||||
| 
 | ||||
|         $isRootAdmin = array_key_exists('root_admin', $data) && $data['root_admin']; | ||||
|  | ||||
| @ -6,6 +6,7 @@ use Illuminate\Support\Facades\Schema; | ||||
| use Illuminate\Database\Schema\Blueprint; | ||||
| use Illuminate\Database\Migrations\Migration; | ||||
| use App\Contracts\Repository\DaemonKeyRepositoryInterface; | ||||
| use Illuminate\Support\Str; | ||||
| 
 | ||||
| return new class extends Migration | ||||
| { | ||||
| @ -21,7 +22,7 @@ return new class extends Migration | ||||
|             $inserts[] = [ | ||||
|                 'user_id' => $server->owner_id, | ||||
|                 'server_id' => $server->id, | ||||
|                 'secret' => DaemonKeyRepositoryInterface::INTERNAL_KEY_IDENTIFIER . str_random(40), | ||||
|                 'secret' => DaemonKeyRepositoryInterface::INTERNAL_KEY_IDENTIFIER . Str::random(40), | ||||
|                 'expires_at' => Carbon::now()->addMinutes(config('panel.api.key_expire_time', 720))->toDateTimeString(), | ||||
|                 'created_at' => Carbon::now()->toDateTimeString(), | ||||
|                 'updated_at' => Carbon::now()->toDateTimeString(), | ||||
|  | ||||
| @ -5,6 +5,7 @@ use Illuminate\Support\Facades\Schema; | ||||
| use Illuminate\Database\Schema\Blueprint; | ||||
| use Illuminate\Database\Migrations\Migration; | ||||
| use App\Contracts\Repository\DaemonKeyRepositoryInterface; | ||||
| use Illuminate\Support\Str; | ||||
| 
 | ||||
| return new class extends Migration | ||||
| { | ||||
| @ -19,7 +20,7 @@ return new class extends Migration | ||||
|             $inserts[] = [ | ||||
|                 'user_id' => $subuser->user_id, | ||||
|                 'server_id' => $subuser->server_id, | ||||
|                 'secret' => DaemonKeyRepositoryInterface::INTERNAL_KEY_IDENTIFIER . str_random(40), | ||||
|                 'secret' => DaemonKeyRepositoryInterface::INTERNAL_KEY_IDENTIFIER . Str::random(40), | ||||
|                 'expires_at' => Carbon::now()->addMinutes(config('panel.api.key_expire_time', 720))->toDateTimeString(), | ||||
|                 'created_at' => Carbon::now()->toDateTimeString(), | ||||
|                 'updated_at' => Carbon::now()->toDateTimeString(), | ||||
|  | ||||
| @ -1,5 +1,6 @@ | ||||
| <?php | ||||
| 
 | ||||
| use Illuminate\Support\Str; | ||||
| use Ramsey\Uuid\Uuid; | ||||
| use Illuminate\Support\Facades\DB; | ||||
| use Illuminate\Support\Facades\Schema; | ||||
| @ -51,7 +52,7 @@ return new class extends Migration | ||||
|         DB::transaction(function () { | ||||
|             DB::table('service_options')->select(['id', 'tag'])->get()->each(function ($option) { | ||||
|                 DB::table('service_options')->where('id', $option->id)->update([ | ||||
|                     'tag' => str_random(10), | ||||
|                     'tag' => Str::random(10), | ||||
|                 ]); | ||||
|             }); | ||||
|         }); | ||||
|  | ||||
| @ -6,6 +6,7 @@ use Illuminate\Support\Facades\Schema; | ||||
| use Illuminate\Database\Schema\Blueprint; | ||||
| use Illuminate\Database\Migrations\Migration; | ||||
| use Illuminate\Contracts\Encryption\DecryptException; | ||||
| use Illuminate\Support\Str; | ||||
| 
 | ||||
| return new class extends Migration | ||||
| { | ||||
| @ -19,7 +20,7 @@ return new class extends Migration | ||||
|                 try { | ||||
|                     $decrypted = Crypt::decrypt($item->secret); | ||||
|                 } catch (DecryptException $exception) { | ||||
|                     $decrypted = str_random(32); | ||||
|                     $decrypted = Str::random(32); | ||||
|                 } finally { | ||||
|                     DB::table('api_keys')->where('id', $item->id)->update([ | ||||
|                         'secret' => $decrypted, | ||||
| @ -66,7 +67,7 @@ return new class extends Migration | ||||
|         DB::transaction(function () { | ||||
|             DB::table('api_keys')->get()->each(function ($item) { | ||||
|                 DB::table('api_keys')->where('id', $item->id)->update([ | ||||
|                     'public' => str_random(16), | ||||
|                     'public' => Str::random(16), | ||||
|                     'secret' => Crypt::encrypt($item->secret), | ||||
|                 ]); | ||||
|             }); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Charles
						Charles