Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Console/ClientCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,6 @@ protected function createAuthCodeClient(ClientRepository $clients)
protected function outputClientDetails(Client $client)
{
$this->line('<comment>Client ID:</comment> '.$client->id);
$this->line('<comment>Client secret:</comment> '.$client->secret);
$this->line('<comment>Client secret:</comment> '.$client->plainSecret);
}
}
55 changes: 55 additions & 0 deletions src/Console/HashCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace Laravel\Passport\Console;

use Illuminate\Console\Command;
use Laravel\Passport\Passport;

class HashCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'passport:hash';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Hash all of the existing secrets in the clients table';

/**
* Execute the console command.
*
* @return void
*/
public function handle()
{
if (! Passport::$hashesClientSecrets) {
$this->warn("Please enable client hashing yet in your AppServiceProvider before continuning.");

return;
}

if ($this->confirm('Are you sure you want to hash all client secrets? This cannot be undone.')) {
$model = Passport::clientModel();

foreach ((new $model)->whereNotNull('secret')->cursor() as $client) {
if (password_get_info($client->secret)['algo'] === PASSWORD_BCRYPT) {
continue;
}

$client->timestamps = false;

$client->forceFill([
'secret' => password_hash($client->secret, PASSWORD_BCRYPT),
])->save();
}

$this->info('All client secrets were successfully hashed.');
}
}
}
1 change: 1 addition & 0 deletions src/PassportServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function boot()
$this->commands([
Console\InstallCommand::class,
Console\ClientCommand::class,
Console\HashCommand::class,
Console\KeysCommand::class,
Console\PurgeCommand::class,
]);
Expand Down