Using libcurl on visual c++ to login to a website, What can be considered a successful login?

134 views Asked by At

When I try to use libcurl on visual c++ to login to a website, I find the example in the website https://www.hackthissite.org/articles/read/1078. I running the instance, and the code as follows:

int main()
{

    curl_global_init( CURL_GLOBAL_ALL );
    CURL * myHandle = curl_easy_init ( );

    // Set up a couple initial paramaters that we will not need to mofiy later.
    curl_easy_setopt(myHandle, CURLOPT_USERAGENT, "Mozilla/4.0");
    curl_easy_setopt(myHandle, CURLOPT_AUTOREFERER, 1 );
    curl_easy_setopt(myHandle, CURLOPT_FOLLOWLOCATION, 1 );
    curl_easy_setopt(myHandle, CURLOPT_COOKIEFILE, "");

    // Visit the login page once to obtain a PHPSESSID cookie
    curl_easy_setopt(myHandle, CURLOPT_URL, "http://www.hackthissite.org/user/login/");
    curl_easy_perform( myHandle );


    // Now, can actually login. First we forge the HTTP referer field, or HTS will deny the login
    curl_easy_setopt(myHandle, CURLOPT_REFERER, "http://www.hackthissite.org/user/login/");
    // Next we tell LibCurl what HTTP POST data to submit
    char *data="username=myname&password=mypwd";
    curl_easy_setopt(myHandle, CURLOPT_POSTFIELDS, data);
    curl_easy_perform( myHandle );
    curl_easy_cleanup( myHandle );

    return 0;
}

The above program running ok, but the console only output the html. I don't konw the login is correct or not? What can be considered a successful login? When I use the wrong password, the program also running ok without errors or bugs.

I find the above question through google and stackoverflow for many pages, but I can't find the correct result. Please help me! Thanks very much!

1

There are 1 answers

4
Thomas Sparber On

In this case it is very specific to the Website you are trying to log on. You Need to validate the HTML result from the Website.