@param OutputInterface $output
@param $username
@param $email
@param $password

@return int|string
16113
private function createAdminUser(OutputInterface $output, $username, $email, $password)
    {
        $output->write('> Create an admin user', true);
        $arguments = [
            'command' => 'fos:user:create',
            'username' => $username,
            'email' => $email,
            'password' => $password,
            '--super-admin' => true,
        ];

        $input = new ArrayInput($arguments);

        return $this->getApplication()->run($input, $output);
    }
324376
private function createSuperAdmin(Command $command, OutputInterface $output)
    {
        $groupRepository = $this->container->get('ekyna_user.group.repository');
        $userRepository = $this->container->get('ekyna_user.user.repository');

        /** @var \Ekyna\Bundle\UserBundle\Model\GroupInterface $group */
        if (null === $group = $groupRepository->findOneBy(['name' => array_keys($this->defaultGroups)[0]])) {
            $output->writeln('Super admin group not found, aborting.');
            return;
        }

        /** @var \Ekyna\Bundle\UserBundle\Model\UserInterface $superAdmin */
        if (null !== $superAdmin = $userRepository->findOneBy(['group' => $group])) {
            $output->writeln(sprintf('Super admin already exists (<comment>%s</comment>).', $superAdmin->getEmail()));
            return;
        }

        $output->writeln('<question>Please provide initial informations ...</question>');

        /** @var \Symfony\Component\Console\Helper\DialogHelper $dialog */
        $dialog = $command->getHelperSet()->get('dialog');

        $email = $dialog->askAndValidate($output, 'Email: ', function ($answer) use ($userRepository) {
            if (!filter_var($answer, FILTER_VALIDATE_EMAIL)) {
                throw new \RuntimeException('This is not a valid email address.');
            }
            if (null !== $userRepository->findOneBy(['email' => $answer])) {
                throw new \RuntimeException('This email address is already used.');
            }
            return $answer;
        }, 3);

        $password = $dialog->askAndValidate($output, 'Password: ', function ($answer) {
            if (!(preg_match('#^[a-zA-Z0-9]+$#', $answer) && strlen($answer) > 5)) {
                throw new \RuntimeException('Password should be composed of at least 6 letters and numbers.');
            }
            return $answer;
        }, 3);

        $notBlankValidator = function ($answer) {
            if (0 === strlen($answer)) {
                throw new \RuntimeException('This cannot be blank.');
            }
            return $answer;
        };

        $firstName = $dialog->askAndValidate($output, 'First name: ', $notBlankValidator, 3);
        $lastName = $dialog->askAndValidate($output, 'Last name: ', $notBlankValidator, 3);

        $userManager = $this->container->get('fos_user.user_manager');
        /** @var \Ekyna\Bundle\UserBundle\Model\UserInterface $user */
        $user = $userManager->createUser();
        $user
            ->setGroup($group)
            ->setGender('mr')
            ->setFirstName($firstName)
            ->setLastName($lastName)
            ->setPlainPassword($password)
            ->setEmail($email)
            ->setEnabled(true);
        $userManager->updateUser($user);

        $output->writeln('Super Admin has been successfully created.');
    }
910022
protected function execute(InputInterface $input, OutputInterface $output): ?int
    {
        $username = $this->getUsername($input, $output);
        $user = $this->findUser($output, $username);
        if (null === $user) {
            return 1;
        }

        $password = $this->getPassword($input, $output);
        if ($password) {
            $this->userManager->setPlainTextPassword($user, $password);
        } else {
            $this->userManager->requestNewPassword($user);
        }
        $this->userManager->save($user);

        if ($password) {
            $message = $this->translator->trans(
                'user.password_changed_success',
                ['%username%' => $username],
                'security'
            );
        } else {
            $message = $this->translator->trans(
                'user.password_request_sent',
                ['%username%' => $username],
                'security'
            );
        }
        $output->writeln("<info>{$message}</info>");

        return 0;
    }
646660
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $errOutput = $output instanceof ConsoleOutputInterface ? $output->getErrorOutput() : $output;
        $output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
        $errOutput->setVerbosity(OutputInterface::VERBOSITY_NORMAL);

        $batchSize = NumberUtils::bound($input->getOption('batch-size'), 1, 2000);
        $batchDelay = NumberUtils::bound($input->getOption('batch-delay'), 10, 600000);
        $context = json_decode($input->getOption('context') ?: '{}', true);
        $context['tenant_id'] = (string)$input->getOption('tenant-id');
        $context['exporting'] = true;
        $qname = $input->getArgument('qname') ? SchemaQName::fromString($input->getArgument('qname')) : null;
        $context['exporting_all'] = null === $qname;

        $i = 0;

        $receiver = function (Node $node) use ($errOutput, $batchSize, $batchDelay, &$i) {
            ++$i;

            try {
                echo json_encode($node) . PHP_EOL;
            } catch (\Exception $e) {
                $errOutput->writeln($e->getMessage());
            }

            if (0 === $i % $batchSize) {
                if ($batchDelay > 0) {
                    usleep($batchDelay * 1000);
                }
            }
        };

        foreach ($this->getSchemasUsingMixin(NodeV1Mixin::create(), (string)$qname ?: null) as $schema) {
            $this->ncr->pipeNodes($schema->getQName(), $receiver, $context);
        }
    }
67445
private function output(OutputInterface $output, array $response)
    {
        $this->printList($output,
            ['Name', 'Key', 'Type', 'Public', 'Outdated', 'Updated At', 'Bad Licenses', 'Unknown Licenses'],
            ['name', 'id', 'project_type', 'public', 'out_number', 'updated_at', 'licenses_red', 'licenses_unknown'],
            $response,
            function ($key, $value) use ($output) {
                if (in_array($key, ['Outdated', 'Bad Licenses', 'Unknown Licenses'], true)) {
                    return $this->printBoolean($output, $value === 0 ? 'No' : $value, $value, !$value, false);
                }

                return $value;
            }
        );

        $this->printTable($output,
            ['Name', 'Stable', 'Outdated', 'Current', 'Requested', 'Licenses', 'Vulnerabilities'],
            ['name', 'stable', 'outdated', 'version_current', 'version_requested', 'licenses', 'security_vulnerabilities'],
            $response['dependencies'],
            function ($key, $value) use ($output) {
                if ('licenses' === $key) {
                    return implode(', ', array_column($value, 'name'));
                }
                if ('stable' === $key) {
                    return $this->printBoolean($output, 'Yes', 'No', $value, false);
                }
                if ('outdated' === $key) {
                    return $this->printBoolean($output, 'No', 'Yes', !$value, false);
                }

                if ('security_vulnerabilities' === $key) {
                    if (is_array($value)) {
                        return $this->printBoolean($output, 'No', implode(', ', array_column($value, 'cve')), count($value) === 0, false);
                    }

                    return $this->printBoolean($output, 'No', 'Yes', true, false);
                }

                return $value;
            }
        );
    }
421517
protected function execute(InputInterface $input, OutputInterface $output)
    {
        if (null === $this->em) {
            $this->em = $this->getContainer()->get('doctrine.orm.entity_manager');
            $this->groupManager = $this->getContainer()->get('fos_user.group_manager');
            $this->userClassname = $this->getContainer()->getParameter('fos_user.model.user.class');
            $this->defaultLocale = $this->getContainer()->getParameter('kunstmaan_admin.default_admin_locale');
        }

        $username = $input->getArgument('username');
        $email = $input->getArgument('email');
        $password = $input->getArgument('password');
        $locale = $input->getArgument('locale');
        $superAdmin = $input->getOption('super-admin');
        $inactive = $input->getOption('inactive');
        $groupOption = $input->getOption('group');

        if (null === $locale) {
            $locale = $this->defaultLocale;
        }
        $command = $this->getApplication()->find('fos:user:create');
        $arguments = array(
            'command' => 'fos:user:create',
            'username' => $username,
            'email' => $email,
            'password' => $password,
            '--super-admin' => $superAdmin,
            '--inactive' => $inactive,
        );

        $input = new ArrayInput($arguments);
        $command->run($input, $output);

        // Fetch user that was just created
        $user = $this->em->getRepository($this->userClassname)->findOneBy(array('username' => $username));

        // Attach groups
        $groupOutput = [];

        foreach (explode(',', $groupOption) as $groupId) {
            if ((int) $groupId === 0) {
                foreach ($this->groups as $value) {
                    if ($groupId === $value->getName()) {
                        $group = $value;

                        break;
                    }
                }
            } else {
                $group = $this->groups[$groupId];
            }

            if (isset($group) && $group instanceof Group) {
                $groupOutput[] = $group->getName();
                $user->getGroups()->add($group);
            } else {
                throw new \RuntimeException(
                    'The selected group(s) can\'t be found.'
                );
            }
        }

        // Set admin interface locale and enable password changed
        $user->setAdminLocale($locale);
        $user->setPasswordChanged(true);

        // Persist
        $this->em->persist($user);
        $this->em->flush();

        $output->writeln(sprintf('Added user <comment>%s</comment> to groups <comment>%s</comment>', $input->getArgument('username'), implode(',', $groupOutput)));
    }
1273942
private function getAdministratorPassword(InputInterface $input, OutputInterface $output)
    {
        /**
         * @var QuestionHelper
         */
        $questionHelper = $this->getHelper('question');
        $validator = $this->getPasswordQuestionValidator($output);

        do {
            $passwordQuestion = $this->createPasswordQuestion('Choose password:', $validator);
            $confirmPasswordQuestion = $this->createPasswordQuestion('Confirm password:', $validator);

            $password = $questionHelper->ask($input, $output, $passwordQuestion);
            $repeatedPassword = $questionHelper->ask($input, $output, $confirmPasswordQuestion);

            if ($repeatedPassword !== $password) {
                $output->writeln('<error>Passwords do not match!</error>');
            }
        } while ($repeatedPassword !== $password);

        return $password;
    }
957807
public static function create(string $username, string $email, string $password) : User
    {
        $user = new User();
        $user->username = $username;
        $user->email    = $email;
        $user->status   = self::STATUS_ACTIVE;
        $user->setPassword($password);
        $user->generateAuthKey();
        return $user;
    }
11912
protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $builder = $this->getMenuBuilder($input, $output);
        if ($input->getOption('dump')) {
            $this->dumpCommands($builder, $output);
        } else {
            $builder->build()->open();
        }
        return 0;
    }
1091366
public function actionIndex($email, $password)
    {
        $user = UserModel::findByEmail($email);

        if ($user === null) {
            $this->stdout(Yii::t('yii2mod.user', 'User is not found.') . "\n", Console::FG_RED);
        } else {
            if ($user->resetPassword($password)) {
                $this->stdout(Yii::t('yii2mod.user', 'Password has been changed.') . "\n", Console::FG_GREEN);
            } else {
                $this->stdout(Yii::t('yii2mod.user', 'Error occurred while changing password.') . "\n", Console::FG_RED);
            }
        }

        return self::EXIT_CODE_NORMAL;
    }
640325
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->injectOutputIntoLogger($output, $this->logger);
        $output->writeln($this->crypt->generateKey());
        return 0;
    }
204910
protected function execute(InputInterface $input, OutputInterface $output) : int
    {
        $logger = LoggerHelper::createDefaultLogger($output);

        /** @var string $cacheOption */
        $cacheOption = $input->getOption('cache');
        $fileCache = new FilesystemCache($cacheOption);
        $cache = new SimpleCacheAdapter($fileCache);

        $browscap = new Browscap($cache, $logger);

        /** @var string $uaArgument */
        $uaArgument = $input->getArgument('user-agent');

        try {
            $result = $browscap->getBrowser($uaArgument);
        } catch (Exception $e) {
            $logger->debug($e);

            return 11;
        }

        try {
            $output->writeln(\ExceptionalJSON\encode($result, JSON_PRETTY_PRINT));
        } catch (EncodeErrorException $e) {
            $logger->error($e);

            return 11;
        }

        return 0;
    }
942254
protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->startCommand($output, false);
        $domains = $input->getOption('domain');
        $languages = $input->getOption('language');
        $project = $this->createProjectByInput($input);

        while (true) {
            $randomTranslation = $project->getRandomMissingTranslation(
                $domains,
                $languages
            );

            if (!($randomTranslation instanceof Translation)) {
                $this
                    ->printMessage(
                        $output,
                        'Trans Server',
                        'No more translations for you!'
                    );

                break;
            }

            $masterTranslation = $randomTranslation->getMasterTranslation();
            $translator = new TranslateClient(
                $masterTranslation->getLanguage(),
                $randomTranslation->getLanguage()
            );
            $translation = $translator->translate(
                $masterTranslation->getValue()
            );

            $this
                ->printMessage(
                    $output,
                    'Trans Server',
                    'Language : ' . $randomTranslation->getLanguage()
                );
            $this->printMessage(
                    $output,
                    'Trans Server',
                    'Key : ' . $randomTranslation->getKey()
                );
            $this->printMessage(
                    $output,
                    'Trans Server',
                    'Original : ' . $randomTranslation
                        ->getMasterTranslation()
                        ->getValue()
                );
            $this->printMessage(
                    $output,
                    'Trans Server',
                    'Translation : ' . $translation
                );

            $randomTranslation->setValue($translation);
            $masterStructure = $randomTranslation->getStructure();
            $this->overwriteLastValueFromStructure(
                $masterStructure,
                $translation
            );
            $randomTranslation->setStructure($masterStructure);

            $project
                ->addTranslation($randomTranslation)
                ->save();
            $output->writeln('');
        }

        $this->finishCommand($output);
    }
1114107
protected function showMessage(OutputInterface $output, $instance, $message)
    {
        $methodGet = $this->adapter->getDisplayNameMethod();

        $output->writeln([
            '',
            sprintf($message, strtolower($this->adapter->getShortName()), $instance->$methodGet()),
        ]);
    }
631408
static function tryLogin(\Db\Connection $db, $email, $password) {
    if ($email === null) {
      throw new UserAuthenticationException("Email required for password login.");
    }

    // find the user with the email
    $q = $db->prepare("SELECT users.* FROM users
        JOIN user_passwords ON users.id=user_passwords.user_id
        WHERE email=? AND user_passwords.password_hash=? LIMIT 1");
    $q->execute(array($email, UserPassword::hash($password)));
    if ($user = $q->fetch()) {
      $result = new User($user);
      $result->setIdentity("(password)");
      return $result;
    } else {
      throw new UserAuthenticationMissingAccountException("No such email/password found.");
    }
  }
270811
public function spawnEditor(OutputInterface $output, string $editor, string $filename) : int
    {
        $descriptorspec = [STDIN, STDOUT, STDERR];
        $command = sprintf('%s %s', $editor, escapeshellarg($filename));

        $output->writeln(sprintf('<info>Executing "%s"</info>', $command));

        $process = proc_open($command, $descriptorspec, $pipes);
        return proc_close($process);
    }
475980
public function signin($username, $password)
    {
        $rules = [
            'username' => ['required' => true],
            'password' => ['required' => true],
        ];
        $inputs = [
            'username' => $username,
            'password' => $password,
        ];
        $requireValidate = new Validation($inputs, $rules);
        if ($requireValidate->fail()) {
            Error::set($requireValidate->error()->get());
        }
        $user = new User();
        if (!$user->isUsername($username)) {
            Error::set(__printl('auth:error:username:not:exists'), 'username');
        } else {
            $password_hash = $user->getByWhere('username', $username)[0]['password'];
            if (!Hash::verify($password, $password_hash)) {
                Error::set(__printl('auth:error:password:confirm'), 'password');
            } else {
                $token = $user->getByWhere('username', $username)[0]['token'];
                $email = $user->getByWhere('username', $username)[0]['email'];
                if (__config()->auth->is_verify_email === true) {
                    if ($token !== 'NULL') {
                        $subject = __printl('auth:subject:need:verify');
                        $link = site_base_url().__config()->auth->verification_link.'/'.$token;
                        $html = __printl('auth:body:need:verify');
                        $html = str_replace(':email', $email, $html);
                        $html = str_replace(':link', $link, $html);
                        (new EmailHandler($subject, $html, $email));
                        Error::set(__printl('auth:error:need:verification'), 'email');
                    }
                }
            }
        }
        if (!$user->isLogin()) {
            if ($this->fail() !== true) {
                $salts = $user->getByWhere('username', $username)[0]['salts'];
                Session::set('user', $salts);
                $request = new Request();
                set_cookie('user', $salts, 31104000, '/', $request->getServerName(), false, true);
                $password_hash = $user->getByWhere('username', $username)[0]['password'];
                if (Hash::needsRehash($password_hash) === true) {
                    $hashed = Hash::make($password);
                    $update = new Update();
                    $update->update(['password'=>$hashed], $user->getByWhere('username', $username)[0]['id']);
                }

                Success::set(__printl('auth:success:signin'));
            }
        } else {
            Error::set(__printl('auth:error:already:login'), 'login');
        }
    }