public function afterAddObject($class)
 {
     switch ($class) {
         case Schemas\ShadowAccount::class:
             $encoder = new CryptEncoder();
             foreach ($this->getAttributes()->get('userpassword') as $password) {
                 $password = $encoder->parsePassword($password);
                 $this->password = $password;
                 break;
             }
             break;
         case Schemas\LenticularUser::class:
             $this->roles = $this->getObject(Schemas\LenticularUser::class)->getAuthRoles();
             $this->enable = $this->getRoles() > 0;
             if ($this->getObject(Schemas\LenticularUser::class)->getUid() === null) {
                 $this->getObject(Schemas\LenticularUser::class)->setUid($this->username);
             } else {
                 $this->username = $this->getObject(Schemas\LenticularUser::class)->getUid();
             }
             break;
         case Schemas\InetOrgPerson::class:
             $object = $this->getObject(Schemas\InetOrgPerson::class);
             if ($object->getSn() == null) {
                 $object->setSn($this->username);
             }
             if ($object->getCn() == null) {
                 $object->setCn($this->username);
             }
     }
 }
 public function afterAddObject($class)
 {
     if ($class === Schemas\ShadowAccount::class) {
         $encoder = new CryptEncoder();
         $this->passwords = [];
         foreach ($this->getObject(Schemas\ShadowAccount::class)->getUserPasswords() as $password) {
             $password = $encoder->parsePassword($password);
             $this->passwords[$password->getId()] = $password;
         }
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $helper = $this->getHelper('question');
     // read password
     $password = "";
     if ($input->getArgument('password')) {
         $password = $input->getArgument('password');
     } else {
         $question = new Question('Please enter password:');
         $question->setHidden(true);
         $password = $helper->ask($input, $output, $question);
     }
     $encoder = new CryptEncoder();
     $pw = new Password();
     $pw->setPasswordPlain($password);
     $encoder->encodePassword($pw);
     $output->writeln($pw->getHash());
     return 0;
 }
 /**
  * @param   Request $request
  * @return  Response
  * @Route("/do",name="registraion_do")
  */
 public function registrationAction(Request $request)
 {
     $response = new Response();
     $form = $this->createForm(RegistrationType::class, new User());
     $form->handleRequest($request);
     if ($form->isSubmitted() && $form->isValid()) {
         $em = $this->getDoctrine()->getManager();
         $user = $form->getData();
         if (in_array(strtolower($user->getUsername()), $this->get('cloud.ldap.userprovider')->getUsernames()) || $em->getRepository('CloudRegistrationBundle:User')->findOneByUsername($user->getUsername())) {
             return $response->setContent(json_encode(['successfully' => false, 'errors' => ['message' => 'user exiests']]));
         }
         $password = new Password();
         $password->setPasswordPlain($user->getPassword());
         $encoder = new CryptEncoder();
         $encoder->encodePassword($password);
         $user->setPasswordHash($password->getHash());
         $em->persist($user);
         $em->flush();
     } else {
         return $response->setContent(json_encode(['successfully' => false, 'errors' => ['message' => $form->getErrors(true)->__toString()]]));
     }
     return $response->setContent(json_encode(['successfully' => true, 'message' => 'Your account need to get activated by a admin']));
 }