Thread: Use libcurl to sign into webpage?

  1. #1
    Registered User
    Join Date
    Jun 2018
    Posts
    26

    Use libcurl to sign into webpage?

    See both C++ and page source code below. I want to use libcurl to enter a username and password into the appropriate fields on the webpage and then click the submit button. What changes to the code below do I need to make?




    Code:
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <curl/curl.h>
    #include <curl/types.h>
    #include <curl/easy.h>
    
    
    
    
    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, "my website");
    
    
    
    
    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, "my website");
    // Next we tell LibCurl what HTTP POST data to submit
    char *data="Name/Badge=1234&Password=1234";
    curl_easy_setopt(myHandle, CURLOPT_POSTFIELDS, data);
    
    
    //curl_easy_setopt(myHandle, CURLOPT_POSTFIELDS, 'ctl00$LogInButton[]=Sign in');
    
    
    
    
    curl_easy_perform( myHandle );
    curl_easy_cleanup( myHandle );
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
    }









    HTML


    Code:
    
    <div id="loginForm">
        <div id="loginInput">
            <label for="ctl00_LoginTextBox" id="ctl00_LoginLabel">Name/Badge</label>
    	    <input name="ctl00$LoginTextBox" type="text" id="ctl00_LoginTextBox" class="PopupInput" />
    	</div>
    	<div id="passwordInput">
    	    <label for="ctl00_PasswordTextbox" id="ctl00_PasswordLabel">Password</label>
    	    <input name="ctl00$PasswordTextbox" type="password" id="ctl00_PasswordTextbox" class="PopupInput" />	    
    	</div>
    	<div id="equipmentbox">
            
            
            
            
        </div>
    </div>
    
    
    
    
    <div id="ctl00_LoginButtons">
    		
    	<input type="submit" name="ctl00$LogInButton" value="Sign in" id="ctl00_LogInButton" class="btn" />
    	
    	<input type="submit" name="ctl00$SwitchLoginScreenModeBT" value="Change Password" id="ctl00_SwitchLoginScreenModeBT" class="btn" />

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,452
    Also here.

  3. #3
    Registered User
    Join Date
    Jun 2018
    Posts
    26
    Am I not allowed to post the same thing in multiple forums?

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    3,676
    Quote Originally Posted by aseagle View Post
    Am I not allowed to post the same thing in multiple forums?
    It is considered rude!

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  5. #5
    Registered User
    Join Date
    Jun 2018
    Posts
    26
    oh. Didn't know. Sorry!

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,498
    That aside, have you done as I suggested previously, and studied what a browser does when observed using wireshark.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    Registered User
    Join Date
    Jun 2018
    Posts
    26
    The issue with that is I am doing this on a work computer and I cannot download software like that without admin permission (which I don't have).

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    37,498
    If your work place won't provide you with the tools you need to do the job, then you need to address that issue.

    Wireshark is absolutely essential for any serious network analysis and debugging.

    Also, does your employer have the licence or permission to go scraping the 3rd party website.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using libcurl to log into Twitter
    By JohnDou in forum Tech Board
    Replies: 3
    Last Post: 12-15-2015, 01:32 PM
  2. Using libcurl to log into Twitter
    By JohnDou in forum C Programming
    Replies: 0
    Last Post: 12-15-2015, 12:50 AM
  3. libcURL PUT Request
    By mrJTparadise in forum C Programming
    Replies: 6
    Last Post: 04-26-2014, 12:06 AM
  4. libcurl and Javascript
    By Rodaxoleaux in forum C++ Programming
    Replies: 6
    Last Post: 12-24-2011, 02:42 PM
  5. help with libcurl
    By ltcabral in forum C Programming
    Replies: 2
    Last Post: 03-27-2008, 01:05 PM

Tags for this Thread