5 * Contains \Drupal\Console\Command\User\PasswordHashCommand.
8 namespace Drupal\Console\Command\User;
10 use Symfony\Component\Console\Input\InputInterface;
11 use Symfony\Component\Console\Input\InputArgument;
12 use Symfony\Component\Console\Output\OutputInterface;
13 use Symfony\Component\Console\Command\Command;
14 use Drupal\Console\Core\Command\Shared\CommandTrait;
15 use Drupal\Core\Password\PasswordInterface;
16 use Drupal\Console\Command\Shared\ConfirmationTrait;
17 use Drupal\Console\Core\Style\DrupalStyle;
19 class PasswordHashCommand extends Command
22 use ConfirmationTrait;
25 * @var PasswordInterface
30 * PasswordHashCommand constructor.
32 * @param PasswordInterface $password
34 public function __construct(PasswordInterface $password)
36 $this->password = $password;
37 parent::__construct();
43 protected function configure()
46 ->setName('user:password:hash')
47 ->setDescription($this->trans('commands.user.password.hash.description'))
48 ->setHelp($this->trans('commands.user.password.hash.help'))
49 ->addArgument('password', InputArgument::IS_ARRAY, $this->trans('commands.user.password.hash.options.password'));
55 protected function execute(InputInterface $input, OutputInterface $output)
57 $io = new DrupalStyle($input, $output);
59 $passwords = $input->getArgument('password');
62 $this->trans('commands.user.password.hash.messages.password'),
63 $this->trans('commands.user.password.hash.messages.hash'),
67 foreach ($passwords as $password) {
70 $this->password->hash($password),
74 $io->table($tableHeader, $tableRows, 'compact');
80 protected function interact(InputInterface $input, OutputInterface $output)
82 $io = new DrupalStyle($input, $output);
84 $passwords = $input->getArgument('password');
89 $this->trans('commands.user.password.hash.questions.password'),
91 function ($pass) use ($passwords, $io) {
92 if (!empty($pass) || count($passwords) >= 1) {
100 sprintf($this->trans('commands.user.password.hash.questions.invalid-pass'), $pass)
108 if ($password && !is_string($password)) {
112 if (is_string($password)) {
113 $passwords[] = $password;
117 $input->setArgument('password', $passwords);