setPassword() public method

Set password
public setPassword ( string $password ) : Newscoop\Entity\User
$password string
return Newscoop\Entity\User
 public function setUp()
 {
     parent::setUp('Newscoop\\Entity\\User', 'Newscoop\\Entity\\Acl\\Role');
     $this->service = new DoctrineAuthService($this->em);
     $this->user = new User();
     $this->user->setEmail(self::EMAIL);
     $this->user->setUsername(self::USERNAME);
     $this->user->setPassword(self::PASSWORD);
     $this->em->persist($this->user);
     $this->em->flush();
 }
 public function setPassword($password)
 {
     $this->__load();
     return parent::setPassword($password);
 }
Example #3
0
 /**
  * Create new activated user
  *
  * @param string  $email
  * @param string  $password
  * @param string  $firstName
  * @param string  $lastName
  * @param integer $publication
  */
 public function createUser($email, $password, $username, $firstName = null, $lastName = null, $publication = 0, $public = true, $userTypes = array(), $isAdmin = false)
 {
     $users = $this->findBy(array('email' => $email));
     if (!empty($users)) {
         throw new \Newscoop\Exception\ResourcesConflictException("User with this email already exists");
     }
     $user = new User($email);
     $user->setPassword($password);
     $user->setUsername($username);
     $user->setPublic($public);
     $user->setActive();
     $user->setFirstName($firstName);
     $user->setLastName($lastName);
     $user->setPublication($publication);
     $user->setAdmin($isAdmin);
     foreach ($userTypes as $type) {
         $user->addUserType($this->em->getReference('Newscoop\\Entity\\User\\Group', $type));
     }
     $this->em->persist($user);
     $this->em->flush();
     return $user;
 }
Example #4
0
 public function testSetPassword()
 {
     $user = new User();
     $user->setPassword('test');
     $property = new \ReflectionProperty($user, 'password');
     $property->setAccessible(TRUE);
     $this->assertTrue($user->checkPassword('test'));
     $this->assertFalse($user->checkPassword('test1'));
     $hash = $property->getValue($user);
     $user->setPassword('test');
     $this->assertNotEquals($hash, $property->getValue($user));
     // expect different hash for same password
     $property->setValue($user, sha1('test'));
     $this->assertFalse($user->checkPassword('test1'));
     $this->assertEquals(sha1('test'), $property->getValue($user));
     $this->assertTrue($user->checkPassword('test'));
     $this->assertNotEquals(sha1('test'), $property->getValue($user));
     // expect password update on check
     $this->assertNotEquals($hash, $property->getValue($user));
     // different from old
     $this->assertTrue($user->checkPassword('test'));
     $this->assertFalse($user->checkPassword(sha1('test')));
 }