示例#1
0
 /**
  * Build a new user and return it.
  *
  * @param string $username the user name
  * @param string $fullname the full name
  * @param string $role     the role, as remembered in LoadRoleData
  *
  * @return User
  */
 private function buildUser($username, $fullname, $role)
 {
     $user = new User();
     $user->setUsername($username);
     $user->setFullname($fullname);
     $user->setIsActive(true);
     $user->addRole($this->getReference($role));
     $user->setInstitution("");
     $user->generateSalt();
     $encoder = $this->container->get('security.encoder_factory')->getEncoder($user);
     $user->setPassword($encoder->encodePassword('supersecret', $user->getSalt()));
     return $user;
 }
示例#2
0
 /**
  * test the salt generation.
  */
 public function testGenerateSalt()
 {
     $user = new User();
     $user->generateSalt();
     $this->assertRegexp('/^[0-9a-f]{32}$/', $user->getSalt());
 }