cURL / Mailing Lists / curl-library / Single Mail

curl-library

Https connect (user+password)

From: Naved Khan <navedk_at_cybage.com>
Date: Thu, 8 May 2003 12:39:45 +0530

Hi,

I am implementing a C++ HTTPS wrapper over libcurl. I need to implement the
following method:

/**
 * Opens a communications link to the resource referenced by the server
name, if such a connection has not already been established. The servername
is any https server.
* @param servername: description of remote server by its URL or IP address.
For
 * example 140.17.28.255 or xyz.abc.net
* @param username – the login to this server
* @param password – the password for the given login.
* @return HttpsStatus – the error code (or success)
**/
HttpsStatus Connect(char* pszServer, char* pszUserID, char* pszPassword)

Dan mentioned below that this is completely site specific. So according to
my understanding, the site should have a password protected page which I
will try to get using curl...Something like:

        m_CurlReturnCode = curl_easy_setopt(m_pCurlHandle, CURLOPT_URL, pszServer);

        int nLen = strlen(pszUserID) + strlen(pszPassword) + 2;
        char* pszUserPwd = new char[nLen];
        sprintf(pszUserPwd, "%s:%s", pszUserID, pszPassword);

        m_CurlReturnCode = curl_easy_setopt(m_pCurlHandle, CURLOPT_USERPWD,
pszUserPwd);
        m_CurlReturnCode = curl_easy_perform(m_pCurlHandle);

In case the user+password fails, the Return code will indicate the error. Is
this the only way? Can we test the connection to the server in any other way
using libcurl than trying to get a page?

Thanks in advance,
Naved

-----Original Message-----
From: Dan Fandrich [mailto:dan_at_coneharvesters.com]
Sent: Wednesday, May 07, 2003 3:15 AM
To: CurlMailing (E-mail)
Subject: Re: User+Password validation?

On Wed, May 07, 2003 at 01:46:16AM +0530, Naved Khan wrote:
> Hi,
>
> Many appologies if this question is very elementary.
>
> I have built a HTTPS wrapper over libcurl. I'm posting an XML request and
> displaying the returned headers, XML response, HTTPS code etc.
> I have a function called connect which is the first funtion called.
> int Connect(const char* szServer, const char* szUserID, const char*
szPassword)
>
> Later, after all the options are set, char* GetResponse() is called which
> returns the XML response. This is the main function where
curl_easy_perform is
> called for HTTPS post.
>
> I wanted to check if the server is valid in the Connect function defined
above
> so I can return the error code(if any) immediately. Is there any way to
do it?
> Just want to check if given user + password works for the given server.
I'm
> looking into it also. Any help will be highy appreciated.

This is an entirely site-specific function; there's no generic way to do it.
If you can identify a safe password-protected page on the site (e.g. /), you
can do a complete HTTP transaction on that page using the HTTP HEAD command
and see if you get a success code. Unless you're calling GetResponse lots
of
times for every Connect and you server supports keep-alive, you'll be
doubling the work for every useful transaction.

>>> Dan

--
http://www.MoveAnnouncer.com              The web change of address service
          Let webmasters know that your web site has moved
-------------------------------------------------------
Enterprise Linux Forum Conference & Expo, June 4-6, 2003, Santa Clara
The only event dedicated to issues related to Linux enterprise solutions
www.enterpriselinuxforum.com
-------------------------------------------------------
Enterprise Linux Forum Conference & Expo, June 4-6, 2003, Santa Clara
The only event dedicated to issues related to Linux enterprise solutions
www.enterpriselinuxforum.com
Received on 2003-05-08