2019-11-29 20:28:34 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Console\Commands\Traits;
|
|
|
|
|
2019-11-29 20:51:21 +00:00
|
|
|
/**
|
2020-09-06 21:20:42 +00:00
|
|
|
* @method void error($message, $verbosity = null)
|
2019-11-29 20:51:21 +00:00
|
|
|
* @method mixed secret($message, $fallback = true)
|
|
|
|
*/
|
2019-11-29 20:28:34 +00:00
|
|
|
trait AskForPassword
|
|
|
|
{
|
|
|
|
private function askForPassword(): string
|
|
|
|
{
|
|
|
|
do {
|
|
|
|
$password = $this->secret('Your desired password');
|
|
|
|
|
|
|
|
if (!$password) {
|
|
|
|
$this->error('Passwords cannot be empty. You know that.');
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$confirmedPassword = $this->secret('Again, just to be sure');
|
|
|
|
} while (!$this->comparePasswords($password, $confirmedPassword ?? null));
|
|
|
|
|
|
|
|
return $password;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function comparePasswords(?string $password, ?string $confirmedPassword): bool
|
|
|
|
{
|
|
|
|
if (!$password || !$confirmedPassword) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp($password, $confirmedPassword) !== 0) {
|
|
|
|
$this->error('The passwords do not match. Try again maybe?');
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|