X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FUser%2FPasswordHashCommand.php;fp=vendor%2Fdrupal%2Fconsole%2Fsrc%2FCommand%2FUser%2FPasswordHashCommand.php;h=208fe98ae03eae870923a4f795dbcbafecdded98;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/vendor/drupal/console/src/Command/User/PasswordHashCommand.php b/vendor/drupal/console/src/Command/User/PasswordHashCommand.php new file mode 100644 index 000000000..208fe98ae --- /dev/null +++ b/vendor/drupal/console/src/Command/User/PasswordHashCommand.php @@ -0,0 +1,120 @@ +password = $password; + parent::__construct(); + } + + /** + * {@inheritdoc} + */ + protected function configure() + { + $this + ->setName('user:password:hash') + ->setDescription($this->trans('commands.user.password.hash.description')) + ->setHelp($this->trans('commands.user.password.hash.help')) + ->addArgument('password', InputArgument::IS_ARRAY, $this->trans('commands.user.password.hash.options.password')); + } + + /** + * {@inheritdoc} + */ + protected function execute(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + $passwords = $input->getArgument('password'); + + $tableHeader = [ + $this->trans('commands.user.password.hash.messages.password'), + $this->trans('commands.user.password.hash.messages.hash'), + ]; + + $tableRows = []; + foreach ($passwords as $password) { + $tableRows[] = [ + $password, + $this->password->hash($password), + ]; + } + + $io->table($tableHeader, $tableRows, 'compact'); + } + + /** + * {@inheritdoc} + */ + protected function interact(InputInterface $input, OutputInterface $output) + { + $io = new DrupalStyle($input, $output); + + $passwords = $input->getArgument('password'); + if (!$passwords) { + $passwords = []; + while (true) { + $password = $io->ask( + $this->trans('commands.user.password.hash.questions.password'), + '', + function ($pass) use ($passwords, $io) { + if (!empty($pass) || count($passwords) >= 1) { + if ($pass == '') { + return true; + } + + return $pass; + } else { + $io->error( + sprintf($this->trans('commands.user.password.hash.questions.invalid-pass'), $pass) + ); + + return false; + } + } + ); + + if ($password && !is_string($password)) { + break; + } + + if (is_string($password)) { + $passwords[] = $password; + } + } + + $input->setArgument('password', $passwords); + } + } +}