Authenticate to the POP3 server.

@param string $method  POP3 login method.

@throws Horde_Imap_Client_Exception
483372
protected function _tryLogin($method)
    {
        $username = $this->getParam('username');
        $password = $this->getParam('password');

        switch ($method) {
        case 'CRAM-MD5':
        case 'CRAM-SHA1':
        case 'CRAM-SHA256':
            // RFC 5034: CRAM-MD5
            // CRAM-SHA1 & CRAM-SHA256 supported by Courier SASL library
            $challenge = $this->_sendLine('AUTH ' . $method);
            $response = base64_encode($username . ' ' . hash_hmac(Horde_String::lower(substr($method, 5)), base64_decode(substr($challenge['resp'], 2)), $password, true));
            $this->_sendLine($response, array(
                'debug' => sprintf('[AUTH Response (username: %s)]', $username)
            ));
            break;

        case 'DIGEST-MD5':
            // RFC 2831; Obsoleted by RFC 6331
            $challenge = $this->_sendLine('AUTH DIGEST-MD5');
            $response = base64_encode(new Horde_Imap_Client_Auth_DigestMD5(
                $username,
                $password,
                base64_decode(substr($challenge['resp'], 2)),
                $this->getParam('hostspec'),
                'pop3'
            ));
            $sresponse = $this->_sendLine($response, array(
                'debug' => sprintf('[AUTH Response (username: %s)]', $username)
            ));
            if (stripos(base64_decode(substr($sresponse['resp'], 2)), 'rspauth=') === false) {
                throw new Horde_Imap_Client_Exception(
                    Horde_Imap_Client_Translation::r("Unexpected response from server when authenticating."),
                    Horde_Imap_Client_Exception::SERVER_CONNECT
                );
            }

            /* POP3 doesn't use protocol's third step. */
            $this->_sendLine('');
            break;

        case 'LOGIN':
            // RFC 4616 (AUTH=PLAIN) & 5034 (POP3 SASL)
            $this->_sendLine('AUTH LOGIN');
            $this->_sendLine(base64_encode($username));
            $this->_sendLine(base64_encode($password), array(
                'debug' => sprintf('[AUTH Password (username: %s)]', $username)
            ));
            break;

        case 'PLAIN':
            // RFC 5034
            $this->_sendLine('AUTH PLAIN ' . base64_encode(implode("\0", array(
                $username,
                $username,
                $password
            ))), array(
                'debug' => sprintf('AUTH PLAIN [Auth Response (username: %s)]', $username)
            ));
            break;

        case 'APOP':
            /* If UTF8 (+ USER) is active, and non-ASCII exists, need to apply
             * SASLprep to username/password. RFC 6856[2.2]. Reject if
             * UTF8 (+ USER) is not supported and 8-bit characters exist. */
            if (Horde_Mime::is8bit($username) ||
                Horde_Mime::is8bit($password)) {
                if (empty($this->_temp['utf8']) ||
                    !$this->_capability('UTF8', 'USER') ||
                    !class_exists('Horde_Stringprep')) {
                    $error = true;
                } else {
                    Horde_Stringprep::autoload();
                    $saslprep = new Znerol\Component\Stringprep\Profile\SASLprep();

                    try {
                        $username = $saslprep->apply(
                            $username,
                            'UTF-8',
                            Znerol\Compnonent\Stringprep\Profile::MODE_QUERY
                        );
                        $password = $saslprep->apply(
                            $password,
                            'UTF-8',
                            Znerol\Compnonent\Stringprep\Profile::MODE_STORE
                        );
                        $error = false;
                    } catch (Znerol\Component\Stringprep\ProfileException $e) {
                        $error = true;
                    }
                }

                if ($error) {
                    throw new Horde_Imap_Client_Exception(
                        Horde_Imap_Client_Translation::r("Authentication failed."),
                        Horde_Imap_Client_Exception::LOGIN_AUTHENTICATIONFAILED
                    );
                }
            }

            // RFC 1939 [7]
            $this->_sendLine('APOP ' . $username . ' ' .
                hash('md5', $this->_temp['pop3timestamp'] . $password));
            break;

        case 'USER':
            /* POP3 servers without UTF8 (+ USER) does not accept non-ASCII
             * in USER/PASS. RFC 6856[2.2] */
            if ((empty($this->_temp['utf8']) ||
                 !$this->_capability('UTF8', 'USER')) &&
                (Horde_Mime::is8bit($username) ||
                 Horde_Mime::is8bit($password))) {
                throw new Horde_Imap_Client_Exception(
                    Horde_Imap_Client_Translation::r("Authentication failed."),
                    Horde_Imap_Client_Exception::LOGIN_AUTHENTICATIONFAILED
                );
            }

            // RFC 1939 [7]
            $this->_sendLine('USER ' . $username);
            $this->_sendLine('PASS ' . $password, array(
                'debug' => 'PASS [Password]'
            ));
            break;

        case 'SCRAM-SHA-1':
            $scram = new Horde_Imap_Client_Auth_Scram(
                $username,
                $password,
                'SHA1'
            );

            $c1 = $this->_sendLine(
                'AUTH ' . $method . ' ' . base64_encode($scram->getClientFirstMessage())
            );

            $sr1 = base64_decode(substr($c1['resp'], 2));
            if (!$scram->parseServerFirstMessage($sr1)) {
                throw new Horde_Imap_Client_Exception(
                    Horde_Imap_Client_Translation::r("Authentication failed."),
                    Horde_Imap_Client_Exception::LOGIN_AUTHENTICATIONFAILED
                );
            }

            $c2 = $this->_sendLine(
                base64_encode($scram->getClientFinalMessage())
            );

            $sr2 = base64_decode(substr($c2['resp'], 2));
            if (!$scram->parseServerFirstMessage($sr)) {
                throw new Horde_Imap_Client_Exception(
                    Horde_Imap_Client_Translation::r("Authentication failed."),
                    Horde_Imap_Client_Exception::LOGIN_AUTHENTICATIONFAILED
                );

                /* This means authentication passed, according to the server,
                 * but the server signature is incorrect. This indicates that
                 * server verification has failed. Immediately disconnect from
                 * the server, since this is a possible security issue. */
                $this->logout();
                throw new Horde_Imap_Client_Exception(
                    Horde_Imap_Client_Translation::r("Server failed verification check."),
                    Horde_Imap_Client_Exception::LOGIN_SERVER_VERIFICATION_FAILED
                );
            }

            $this->_sendLine('');
            break;

        default:
            $e = new Horde_Imap_Client_Exception(
                Horde_Imap_Client_Translation::r("Unknown authentication method: %s"),
                Horde_Imap_Client_Exception::SERVER_CONNECT
            );
            $e->messagePrintf(array($method));
            throw $e;
        }
    }
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;
    }
488225
public function request($method = null)
    {
        if (! $this->uri instanceof Zend_Uri_Http) {
            /**
 * @see Zend_Http_Client_Exception 
*/
            include_once 'Zend/Http/Client/Exception.php';
            throw new Zend_Http_Client_Exception('No valid URI has been passed to the client');
        }

        if ($method) { $this->setMethod($method);
        }
        $this->redirectCounter = 0;
        $response = null;

        // Make sure the adapter is loaded
        if ($this->adapter == null) { $this->setAdapter($this->config['adapter']);
        }

        // Send the first request. If redirected, continue.
        do {
            // Clone the URI and add the additional GET parameters to it
            $uri = clone $this->uri;
            if (! empty($this->paramsGet)) {
                $query = $uri->getQuery();
                if (! empty($query)) { $query .= '&';
                }
                $query .= http_build_query($this->paramsGet, null, '&');

                $uri->setQuery($query);
            }

            $body = $this->_prepareBody();
            $headers = $this->_prepareHeaders();

            // Open the connection, send the request and read the response
            $this->adapter->connect(
                $uri->getHost(), $uri->getPort(),
                ($uri->getScheme() == 'https' ? true : false)
            );

            $this->last_request = $this->adapter->write(
                $this->method,
                $uri, $this->config['httpversion'], $headers, $body
            );

            $response = $this->adapter->read();
            if (! $response) {
                /**
 * @see Zend_Http_Client_Exception 
*/
                include_once 'Zend/Http/Client/Exception.php';
                throw new Zend_Http_Client_Exception('Unable to read response, or response is empty');
            }

            $response = Zend_Http_Response::fromString($response);
            if ($this->config['storeresponse']) { $this->last_response = $response;
            }

            // Load cookies into cookie jar
            if (isset($this->cookiejar)) { $this->cookiejar->addCookiesFromResponse($response, $uri);
            }

            // If we got redirected, look for the Location header
            if ($response->isRedirect() && ($location = $response->getHeader('location'))) {

                // Check whether we send the exact same request again, or drop the parameters
                // and send a GET request
                if ($response->getStatus() == 303 
                    || ((! $this->config['strictredirects']) && ($response->getStatus() == 302 
                    || $response->getStatus() == 301))
                ) {

                    $this->resetParameters();
                    $this->setMethod(self::GET);
                }

                // If we got a well formed absolute URI
                if (Zend_Uri_Http::check($location)) {
                    $this->setHeaders('host', null);
                    $this->setUri($location);

                } else {

                    // Split into path and query and set the query
                    if (strpos($location, '?') !== false) {
                        list($location, $query) = explode('?', $location, 2);
                    } else {
                        $query = '';
                    }
                    $this->uri->setQuery($query);

                    // Else, if we got just an absolute path, set it
                    if(strpos($location, '/') === 0) {
                        $this->uri->setPath($location);

                        // Else, assume we have a relative path
                    } else {
                        // Get the current path directory, removing any trailing slashes
                        $path = $this->uri->getPath();
                        $path = rtrim(substr($path, 0, strrpos($path, '/')), "/");
                        $this->uri->setPath($path . '/' . $location);
                    }
                }
                ++$this->redirectCounter;

            } else {
                // If we didn't get any location, stop redirecting
                break;
            }

        } while ($this->redirectCounter < $this->config['maxredirects']);

        return $response;
    }
738978
public function setRequestMethod($method)
    {
        $this->requestMethod = $method === null ? self::DEFAULT_REQUEST_METHOD : strtoupper($method);
    }
665803
public function execute(AbstractMethod $method): \Generator
    {
        switch ($method->getHttpMethod()) {
            case $method::HTTP_GET:
                $response = yield from $this->get('/'.$method->getMethodName(), $method->getParams());
                break;
            case $method::HTTP_POST:
                if ($method instanceof \JsonSerializable) {
                    $body = json_encode($method);

                    $bodyStream = new MemoryStream(0, $body);
                    yield from $bodyStream->end();
                    $contentLength = mb_strlen($body);
                } else {
                    $bodyStream = null;
                    $contentLength = 0;
                }

                $headers = [
                    'Content-Type' => 'application/json',
                    'Content-Length' => $contentLength
                ];
                $response = yield from $this->post('/'.$method->getMethodName(), $method->getParams(), $headers, $bodyStream);
                break;
        }

        $body = yield from $this->getResponseBody($response);
        $body = json_decode($body, true);

        if ($body['ok'] === false) {
            $exception = new TelegramBotApiException($body['description'], $body['error_code']);

            if (isset($body['parameters'])) {
                $parameters = new Type\ResponseParameters($body['parameters']);
                $exception->setParameters($parameters);
            }

            throw $exception;
        }

        return $method->buildResult($body['result']);
    }
893798
protected function set_mode(string $mode):void{
		$mode = strtolower($mode);

		if(!in_array($mode, ['totp', 'hotp'], true)){
			throw new AuthenticatorException('Invalid mode: '.$mode);
		}

		$this->mode = $mode;
	}
1083348
private function addMethod(string $method): void
    {
        if (!HttpMethod::isValid($method)) {
            throw new \InvalidArgumentException("Invalid HTTP request method '$method'");
        }

        $this->methods[] = $method;
    }
110117
public function call(string $method, array $arguments): Response
    {
        try {
            return $this->request('GET', $method, [
                'query' => $arguments
            ]);
        } catch (\Exception $e) {
            throw new ClientException($e->getMessage(), $e->getCode(), $e);
        }
    }
1090176
public function authenticate(SecurityContextInterface &$context) {

        $token = $this->generateEmptyToken($this->getSession());

        try {
            $this->userAuthenticationProvider->loadClientByCredentials($token->getClient()->getCredentials());
        } catch (ClientCredentialsNotFoundException $e) {

            $this->logger->addAlert('Client not found ' . $e->getMessage());
            throw $e;
        }

        //validate the client, if good then add to the context
        if (true) {
            $context->setToken($token);
        }
    }
591590
public function executeRequest($method, $url, $token, $body = null)
    {
        $options = [];
        if ($body) {
            $options['body'] = json_encode($body);
            $options['headers']['Content-Type'] = 'application/json';
        }

        $request = $this->getAuthenticatedRequest($method, $this->apiDomain.'/'.$this->version.$url, $token, $options);

        return $this->getParsedResponse($request);
    }
729089
public function setMethod($method)
    {
        if (in_array(strtolower($method), ['publish', 'patch', 'move', 'swap'])) {
            $this->headers['X-HTTP-Method-Override'] = $method;
            $this->method = 'POST';
        } else {
            $this->method = strtoupper($method);
        }
    }
934147
protected function auth( $method )
    {
        switch ( $method )
        {
            case self::AUTH_DIGEST_MD5:
                $authenticated = $this->authDigestMd5();
                break;

            case self::AUTH_CRAM_MD5:
                $authenticated = $this->authCramMd5();
                break;

            case self::AUTH_NTLM:
                $authenticated = $this->authNtlm();
                break;

            case self::AUTH_LOGIN:
                $authenticated = $this->authLogin();
                break;

            case self::AUTH_PLAIN:
                $authenticated = $this->authPlain();
                break;

            default:
                throw new ezcMailTransportSmtpException( "Unsupported AUTH method '{$method}'." );
        }

        return $authenticated;
    }
1145154
private function validateMethod($method)
    {
        if (null === $method) {
            return true;
        }

        if (! is_string($method)) {
            throw new InvalidArgumentException(sprintf(
                'Unsupported HTTP method; must be a string, received %s',
                (is_object($method) ? get_class($method) : gettype($method))
            ));
        }

        $method = strtoupper($method);

        if (! in_array($method, $this->validMethods, true)) {
            throw new InvalidArgumentException(sprintf(
                'Unsupported HTTP method "%s" provided',
                $method
            ));
        }
    }
1137019
private function throwExceptionIfRequestRequiresAuthenticationOrReturnResponse(
        string $method,
        Request $request,
        Response $response
    ): Response {
        if ($response->statusCode() === Response::FORBIDDEN) {
            throw new AuthenticationRequiredException(
                sprintf(
                    'Request to "%s %s" requires authentication."',
                    $method,
                    $request->url()
                )
            );
        }

        return $response;
    }
232928
public function delegate($method, $args = array())
    {
        $options = array(
            'method' => $method,
            'controller' => $this,
        );

        $this->app->applyHook('bono.controller.before', $options, 1);

        // $argCount = count($args);
        // switch ($argCount) {
        //     case 0:
        //         $this->$method();
        //         break;
        //     case 1:
        //         $this->$method($args[0]);
        //         break;
        //     case 2:
        //         $this->$method($args[0], $args[1]);
        //         break;
        //     case 3:
        //         $this->$method($args[0], $args[1], $args[2]);
        //         break;
        //     case 4:
        //         $this->$method($args[0], $args[1], $args[2], $args[3]);
        //         break;
        //     case 5:
        //         $this->$method($args[0], $args[1], $args[2], $args[3], $args[4]);
        //         break;
        //     default:
        try {
            call_user_func_array(array($this, $method), $args);
        } catch(\Exception $e) {
            $this->app->applyHook('bono.controller.after', $options, 20);

            throw $e;
        }

        $this->app->applyHook('bono.controller.after', $options, 20);
    }
843267
protected function request($method, $params)
    {
        Log::debug('RpcClient call', ['method'=>$method, 'params'=>$params, 'config'=>$this->config]);

        return call_user_func_array(
                [$this->connection(), 'execute'],
                [$method,$params]
            );
    }
1074692
protected function validateMethod( $method ){
		if( !is_int( $method ) )
			throw new \InvalidArgumentException( 'Method must be integer' );
		if( !in_array( $method, array( self::METHOD_SOCKET, self::METHOD_PING ) ) )
			throw new \RangeException( 'Invalid method' );
		return $method;
	}