/**
  * @see \Ableron\Modules\Core\Services\Authentication\AuthenticationInterface::authenticateManually()
  */
 public static function authenticateManually($username, $password)
 {
     // get user in case username exists
     $user = Application::getPersistenceManager()->getRepository('UserEntity')->findByUsername($username);
     // check password
     if ($user !== null && Password::verify($password, $user->getPasswordHash())) {
         // rehash password if necessary
         if (Password::needsRehash($user->getPasswordHash())) {
             $user->setPasswordHash(Password::hash($password));
         }
         // return the user object
         return $user;
     }
     // credentials invalid
     return null;
 }
Пример #2
0
 /**
  * Tests whether verify() works as expected.
  *
  * @return void
  */
 public function testVerify()
 {
     $this->assertTrue(Password::verify('foobar', Password::hash('foobar')));
     $this->assertFalse(Password::verify('foobarbaz', Password::hash('foobar')));
 }
 /**
  * Creates an admin account.
  *
  * @return void
  */
 private function createAdminAccount()
 {
     // create user entity
     $user = new UserEntity($this->getInstaller()->getInstallationParameter('admin.username'), Password::hash($this->getInstaller()->getInstallationParameter('admin.password')), $this->getInstaller()->getInstallationParameter('admin.emailAddress'), $this->getInstaller()->getInstallationParameter('admin.firstName'), $this->getInstaller()->getInstallationParameter('admin.lastName'));
     // assign root role
     $user->getRoles()->add(Application::getPersistenceManager()->getRepository('RoleEntity')->findOneBy(array('name' => 'Root')));
     // write changes to database
     Application::getPersistenceManager()->getEntityManager()->persist($user);
     Application::getPersistenceManager()->getEntityManager()->flush();
 }