public function authenticate(array $credentials) { list($username, $password) = $credentials; $user = $this->model->getByNameOrEmail($username); if (!$user) { throw new AuthenticationException('User not found.', self::IDENTITY_NOT_FOUND); } if (!$this->passwordStrategy->matchPassword($user, $password)) { throw new AuthenticationException('Invalid password.', self::INVALID_CREDENTIAL); } return new Identity($user->getId(), $this->model->getRoles($user)); }