/**
  * @Route("/edit/{user}",name="registration_admin_edit")
  */
 public function editAction(Request $request, $user)
 {
     $response = new Response();
     $em = $this->getDoctrine()->getManager();
     $form = $this->createForm(EditType::class);
     $form->handleRequest($request);
     $user = $em->getRepository(RegUser::class)->findOneByUsername($user);
     if ($form->isValid()) {
         $data = $form->getData();
         if ($data['action'] === true) {
             $password = new Password();
             $password->setHash($user->getPasswordHash());
             $password->setId('default');
             $password->setEncoder(CryptEncoder::class);
             $userLdap = $this->get('cloud.ldap.util.usermanipulator')->createUserObject($user->getUsername(), $password);
             $userLdap->setAltEmail($user->getAltEmail());
             $userLdap->setGpgPublicKey($user->getGpgPublicKey());
             $this->get('cloud.ldap.util.usermanipulator')->create($userLdap);
             $em->remove($user);
         } elseif ($data['action'] === false) {
             $em->remove($user);
         } else {
             $response->setStatusCode(400);
             return $response;
         }
         $em->flush();
     } else {
         $response->setContent(json_encode(['successfully' => false, 'error' => $form->getErrors(true)->__toString()]));
         return $response;
     }
     $response->setContent(json_encode(['successfully' => true]));
     return $response;
 }
 public function testServiceInvalide()
 {
     $service = new Service("");
     $this->assertNotEmpty($this->validator->validate($service));
     $service = new Service("testService");
     $invalidPassword = new Password();
     $invalidPassword->setId("invalidö");
     $invalidPassword->setPasswordPlain("123456");
     $service->addPassword($invalidPassword);
     $this->assertNotEmpty($this->validator->validate($service));
 }
 public function testPasswordInvalide()
 {
     $password = new Password();
     // no plain password and no hash
     $password->setId("valid");
     //$this->assertNotEmpty($this->validator->validate($password));
     $password->setPasswordPlain("123456");
     $password->setId("0");
     $this->assertNotEmpty($this->validator->validate($password));
     $password->setId(null);
     $this->assertNotEmpty($this->validator->validate($password));
     $password->setId("");
     // empty id
     $this->assertNotEmpty($this->validator->validate($password));
     $password->setId("df.");
     // invalide char
     $this->assertNotEmpty($this->validator->validate($password));
     $password->setId("0101sfdgfda");
     // to long
     $this->assertNotEmpty($this->validator->validate($password));
 }
 /**
  * (non-PHPdoc)
  * @see \Cloud\LdapBundle\Security\PasswordEncoderInterface::parsePassword()
  */
 public function parsePassword($password_hash)
 {
     $password = new Password();
     $password->setHash($password_hash);
     $matches = null;
     preg_match('#^{crypt}\\$\\d\\$(rounds=\\d+\\$)?([0-9a-zA-Z_-]+)?(=|\\+)?[0-9a-zA-Z_-]+\\$[^\\$]*$#', $password_hash, $matches);
     if ($matches != null) {
         $password->setId(substr($matches[2], 0, -1));
         $password->setMasterPassword($matches[3] === '+');
     }
     return $password;
 }
 /**
  * (non-PHPdoc)
  * @see \Cloud\LdapBundle\Security\PasswordEncoderInterface::parsePassword()
  */
 public static function parsePassword(Attribute $password_hash)
 {
     $password = new Password();
     $password->setAttribute($password_hash);
     $password->setHash($password_hash->get());
     $password->setId('default');
     /*if(preg_match('#^[0-9A-F]$#',$password_hash->get())===1) {
           $password->setMasterPassword(true);
       }elseif(preg_match('#^[0-9a-f]$#',$password_hash->get())===1) {
           $password->setMasterPassword(false);
       }*/
     $password->setEncoder(NtEncoder::class);
     return $password;
 }
 /**
  * (non-PHPdoc)
  * @see \Cloud\LdapBundle\Security\PasswordEncoderInterface::parsePassword()
  */
 public static function parsePassword(Attribute $password_hash)
 {
     $password = new Password();
     $password->setAttribute($password_hash);
     $matches = null;
     $found = preg_match('#^{crypt}\\$\\d\\$(rounds=\\d+\\$)?([0-9a-zA-Z_-]+)?(=|\\+)[0-9a-zA-Z_-]+\\$[^\\$]*$#', $password_hash->get(), $matches);
     if ($found === 1) {
         $password->setId($matches[2]);
         $password->setMasterPassword($matches[3] === '+');
     } else {
         return null;
     }
     $password->setEncoder(CryptEncoder::class);
     return $password;
 }