/** * Generate one password based on options. * * @return string password * @throws ImpossibleMinMaxLimitsException * @throws \Hackzilla\PasswordGenerator\Exception\CharactersNotFoundException */ public function generatePassword() { if ($this->dirtyCheck) { if (!$this->validLimits()) { throw new ImpossibleMinMaxLimitsException(); } $this->dirtyCheck = false; } do { $password = parent::generatePassword(); } while (!$this->validatePassword($password)); return $password; }
protected function execute(InputInterface $input, OutputInterface $output) { $username = $input->getArgument('username'); if ($input->getArgument('password')) { $password = $input->getArgument('password'); } else { $generator = new ComputerPasswordGenerator(); $generator->setOptionValue(ComputerPasswordGenerator::OPTION_UPPER_CASE, true)->setOptionValue(ComputerPasswordGenerator::OPTION_LOWER_CASE, true)->setOptionValue(ComputerPasswordGenerator::OPTION_NUMBERS, true)->setOptionValue(ComputerPasswordGenerator::OPTION_SYMBOLS, false); $password = $generator->generatePassword(); } $registerUserCommand = new DomainCommand($username, $password); $commandGateway = $this->getContainer()->get('app.command.gateway'); $commandGateway->send($registerUserCommand); $output->writeln('<info>User created!</info>'); }
function __construct() { $generator = new ComputerPasswordGenerator(); $generator->setOptionValue(ComputerPasswordGenerator::OPTION_UPPER_CASE, true)->setOptionValue(ComputerPasswordGenerator::OPTION_LOWER_CASE, true)->setOptionValue(ComputerPasswordGenerator::OPTION_NUMBERS, true); $password = $generator->generatePassword(); $faker = \Faker\Factory::create(); $this->company_name = $faker->company; $this->company_website = $faker->url; $this->contact_person = $faker->name; $this->username = $faker->userName; if (strlen($this->username) <= 8) { $this->username = $this->username . uniqid(); $this->username = substr($this->username, 0, 10); } $this->password = $password; $this->retype_password = $password; $this->street = $faker->streetName; $this->house_number = $faker->randomDigit; $this->post_code = $faker->postcode; $this->city = $faker->city; $this->country = "United States"; $this->email_address = $faker->email; }
/** * @Route("/sign_up", name="sign_up") * @Method({"GET", "POST"}) * * @param Request $request * @return Response */ public function signUpAction(Request $request) { $generator = new ComputerPasswordGenerator(); $generator->setUppercase()->setLowercase()->setNumbers()->setSymbols(false)->setLength(6); $password = $generator->generatePassword(); $users = new Users(); $login = $request->get('first-name'); $email = $request->get('email'); $users->setFirstName($login); $users->setSecondName($request->get('second-name')); $users->setPatronymic($request->get('patronymic')); $users->setEmail($email); $users->setUseReason($request->get('use-reason')); $users->setPassword($password); $em = $this->getDoctrine()->getManager(); try { $em->persist($users); $em->flush(); } catch (\Exception $error) { } $this->mailSend(['login' => $email, 'password' => $password]); return $this->render('default/thanks.html.twig', array('base_dir' => realpath($this->container->getParameter('kernel.root_dir') . '/..'))); }
public function testSimpleUsage() { $generator = new ComputerPasswordGenerator(); $generator->setOptionValue(ComputerPasswordGenerator::OPTION_UPPER_CASE, true)->setOptionValue(ComputerPasswordGenerator::OPTION_LOWER_CASE, true)->setOptionValue(ComputerPasswordGenerator::OPTION_NUMBERS, true)->setOptionValue(ComputerPasswordGenerator::OPTION_SYMBOLS, false); $generator->generatePassword(); }