-
Notifications
You must be signed in to change notification settings - Fork 784
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[9.x] Implement passport:hash command (#1238)
* Implement passport:hash command * Skip records which are already hashed * Fix client command when hashing secrets * Use password_get_info * Update HashCommand.php Co-authored-by: Taylor Otwell <taylor@laravel.com>
- Loading branch information
1 parent
69ccc34
commit 7a39717
Showing
3 changed files
with
57 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.'); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters