Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Implement passport:hash command #1238

Merged
merged 5 commits into from
May 5, 2020
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