Authenticate using email and password credentials

@param DispatcherContext $context A dispatcher context object
@return  boolean Returns TRUE if the authentication explicitly succeeded.
516322
public function authenticateRequest(DispatcherContext $context)
    {
        $request = $context->request;

        if($request->headers->has('Authorization'))
        {
            $authorization = $request->headers->get('Authorization');

            if(stripos($authorization, 'basic') === 0)
            {
                $exploded = explode(':', base64_decode(substr($authorization , 6)));
                if (count($exploded) == 2) {
                    list($username, $password) = $exploded;
                }

                if($username)
                {
                    $user = $this->getObject('user.provider')->getUser($username);

                    if($user->getId())
                    {
                        //Check user password
                        if (!$user->verifyPassword($password)) {
                            throw new ControllerExceptionRequestNotAuthenticated('Wrong password');
                        }

                        //Check user enabled
                        if (!$user->isEnabled()) {
                            throw new ControllerExceptionRequestNotAuthenticated('Account disabled');
                        }

                        //Login the user
                        $this->loginUser($user->getId());

                        return true;
                    }
                    else throw new ControllerExceptionRequestNotAuthenticated('Wrong username');
                }
                else throw new ControllerExceptionRequestNotAuthenticated('Invalid username');
            }
        }
    }
339982
public function hasContext($context)
    {
        if ($this->contextConfiguration && array_key_exists($context, $this->contextConfiguration)) {
            return true;
        }

        return false;
    }
670440
protected function _actionFail(DispatcherContext $context)
    {
        //Check an exception was passed
        if(!isset($context->param) && !$context->param instanceof \Exception)
        {
            throw new \InvalidArgumentException(
                "Action parameter 'exception' [Exception] is required"
            );
        }

        //Get the exception object
        $exception = $context->param;

        //If the error code does not correspond to a status message, use 500
        $code = $exception->getCode();
        if(!isset(HttpResponse::$status_messages[$code])) {
            $code = '500';
        }

        //Get the error message
        $message = $exception->getMessage();
        if(empty($message)) {
            $message = HttpResponse::$status_messages[$code];
        }

        //Store the exception in the context
        $context->exception = $exception;

        //Set the response status
        $context->response->setStatus($code , $message);

        //Send the response
        return $this->send($context);
    }
835053
private function _authenticate($credentials)
    {
        try {
            $response = $this->getService('com:people.authentication.response');
            dispatch_plugin('authentication.onAuthenticate', array(
                                'credentials' => $credentials,
                                'response' => $response
                            ));

            if ($response->status === ComPeopleAuthentication::STATUS_SUCCESS) {
                return true;
            }

        } catch (RuntimeException $e) {
            //only throws exception if we are using JSON format
            //otherwise let the current app handle it
            if (AnRequest::format() == 'json') {
                throw $e;
            }
        }

        return false;
    }
233564
public function checkUserCredentials($credential, $password)
    {
        $user = $this->getUserDataMapper()->findByCredential($credential);

        $userClass = $this->userClass;

        if (! $user instanceof $userClass) {
            return false;
        }

        foreach ($this->userCredentialsStrategies as $strategy) {
            $result = $strategy instanceof UserCredentialsStrategyInterface
                ? $strategy->isValid($user, $password)
                : call_user_func($strategy, $user, $password);

            if (! $result) {
                break;
            }
        }

        return isset($result) ? $result : false;
    }
65077
public function isValid($value, array $context = null)
    {
        $context = (array) $context;

         if (!array_key_exists($this->identity, $context) || empty($context[$this->identity])) {
//             $this->error(self::IDENTITY_EMPTY);
             return false;
         }
        
         if (!array_key_exists($this->credential, $context) || empty($context[$this->credential])) {
//             $this->error(self::CREDENTIAL_EMPTY);
             return false;
         }
        
        $authAdapter = $this->auth->getAdapter();
        $authAdapter->setIdentity($context[$this->identity]);
        $authAdapter->setCredential($context[$this->credential]);
        
        $result = $this->authResult = $this->auth->authenticate();
        
        if (!$result->isValid()) {
            $this->error($result->getCode());
            return false;
        }
        
        return true;
    }
953994
protected function _actionGet(DispatcherContext $context)
    {
        $controller = $this->getController();

        if($controller instanceof ControllerViewable) {
            $result = $controller->execute('render', $controller->getContext($context));
        } else {
            throw new DispatcherExceptionMethodNotAllowed('Method GET not allowed');
        }

        return $result;
    }
1085449
public function appliesToContext(ContextInterface $context): bool
    {
        if (!$context instanceof ClientMethodContext) {
            return false;
        }

        $method = $context->getMethod();
        if (!preg_match($this->regex, $method->getMethodName())) {
            return false;
        }

        return $this->subRule->appliesToContext($context);
    }
290762
protected function checkBypassAccess($context) {
    $bypassAccessChecker = $this->getBypassAccessChecker();
    if(is_null($bypassAccessChecker)) {
      return FALSE;
    }

    $bypassAccess = $bypassAccessChecker->checkBypassAccess($context);
    if(!is_bool($bypassAccess)) {
      throw new InvalidReturnTypeException('The bypass access checker must return a boolean, see Ordermind\LogicalPermissions\BypassAccessCheckerInterface::checkBypassAccess().');
    }

    return $bypassAccess;
  }
432403
public function match(Context $context)
    {
        $name = $this->getName($context);

        if ($this->map->hasRoute($name)) {
            return $this->map->getRoute($name);
        }

        return false;
    }
497576
public function challengeResponse(DispatcherContext $context)
    {
        if($context->request->isGet())
        {
            $token = $context->user->getSession()->getToken();

            $context->response->headers->addCookie($this->getObject('lib:http.cookie', array(
                'name'   => 'csrf_token',
                'value'  => $token,
                'path'   => $context->request->getBaseUrl()->getPath(),
            )));

            $context->response->headers->set('X-CSRF-Token', $token);
        }

        parent::challengeResponse($context);
    }
177401
public function validateUser(AnCommandContext $context)
    {
        $package = $this->getItem();

        //validate user
        if (get_viewer()->guest() && !$this->person->validateEntity()) {
            $url = route('option=com_subscriptions&view=signup&layout=login&id='.$package->id);
            $context->response->setRedirect($url);
            return false;
        }

        return true;
    }
819859
public function authenticate(Credential $credential)
    {
        $username = $credential->username;
        $password = $credential->password;

        if (!$username || !$password) {
            $this->status = Authentication::EMPTY_CREDENTIAL;

            return false;
        }

        foreach ($this->users as $user) {
            if (!isset($user['username'])) {
                continue;
            }

            if ($user['username'] !== $username) {
                continue;
            }

            if (!isset($user['password'])) {
                $this->status = Authentication::INVALID_CREDENTIAL;

                return false;
            }

            $handler = $this->getVerifyHandler();

            if (call_user_func_array($handler, [$password, $user['password']])) {
                $this->status = Authentication::SUCCESS;

                return true;
            }

            $this->status = Authentication::INVALID_CREDENTIAL;

            return false;
        }

        $this->status = Authentication::USER_NOT_FOUND;

        return false;
    }
1064928
protected function _authorizeRemoveAdmin(AnCommandContext $context)
    {
        if ($this->_entity->isAdministrable()) {
            return ($this->_entity->administratorIds->count() >= 2);
        }

        return false;
    }
1311175
protected static function ctxHasCurrentAccount(ContextInterface $context): bool
    {
        /** @var AccountManagerInterface $manager */
        $container = static::ctxGetContainer($context);
        $manager   = $container->get(AccountManagerInterface::class);
        $account   = $manager->getAccount();

        return $account !== null;
    }
1281541
private function authenticateWithPassword()
    {
        if ($this->credentials->havePassword()) {
            $authCommand = new Auth();
            $authCommand->setArguments([$this->credentials->getPassword()]);
            $authResponse = $this->connection->execute($authCommand);
            $response = $authCommand->parse($authResponse);
            if ($response !== self::AUTH_SUCCESS_MESSAGE) {
                throw new AuthenticationException();
            }
        }
    }
1189915
protected function _authorizeSubscribe($context)
    {
        $entity = $this->_entity;

        if (is_guest($this->_viewer)) {
            return false;
        }

        if (! $entity->isSubscribable()) {
            return false;
        }

        return $this->_viewer->following($entity);
    }