Example #1
0
 /**
  * Performs an authentication.
  * @return Nette\Security\Identity
  * @throws Nette\Security\AuthenticationException
  */
 public function authenticate(array $credentials)
 {
     list($username, $password) = $credentials;
     $user = $this->usersFacade->findByName($username);
     if ($user == null) {
         throw new Nette\Security\AuthenticationException('The username is incorrect.', self::IDENTITY_NOT_FOUND);
     } elseif (!Passwords::verify($password, $user->getPassword())) {
         throw new Nette\Security\AuthenticationException('The password is incorrect.', self::INVALID_CREDENTIAL);
     } elseif (Passwords::needsRehash($user->getPassword())) {
         $this->usersFacade->update(array('password' => Passwords::hash($password)));
     }
     $arr = array($user->getUsername(), $user->getEmail(), $user->getDate());
     return new Nette\Security\Identity($user->getId(), $user->getRole(), $arr);
 }