Click here to Skip to main content
13,042,630 members (80,524 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


9 bookmarked
Posted 11 Sep 2012

Programmatic Login to Website

Rate this:
Please Sign up or sign in to vote.
How to login into a website programatically.


In this article I will demonstrate to you how to login into a website programmatically using plain HTML  


While implementing a Single-Sign-On functionality, we need to login into other web applications without manually entering the credentials. The real problem occurs when we need to login into third party websites where we do not have access to the website code and database. In that case you need to simulate the login procedure programmatically on the client side itself so that all the client side cookies and other authentication stuff is created on the client machine itself.

Using the code

Using this approach, you can login into any website programmatically. I am using website for the demonstration.

The first step is to get the HTML source for the login page from the source of the webpage. I am using the HTML for these three HTML elements 'Email', 'Password', and 'SignIn' button. Rightclick on the webpage > View Source and copy the HTML and JavaScript (if any) related to Login functionality. 


This is the HTML I picked from the page source. 

<script type="text/javascript">        //<!-- 
        function doSubmit(secure) {
            if (secure)
                document.subForm.action = ""
                document.subForm.action = ""
            return true;
        } //--> 
	<a name="SignUp"></a> 
	<form name="subForm" id="subForm" 


	   method="post" class="tight"> 
	<input id="FormName" name="FormName" 

	   value="MenuBarForm" type="hidden" /> 
	Email <input class="small-text" type="text" 

	  name="Email" id="Text1" style="width:150px" /> 
	Password <input class="small-text" type="password" 

	  name="Password" id="Password1" style="width:60px" /> 
	<input type="submit" value="Sign in" class="button" 

	  onclick="return doSubmit(false);" />

We need to do a little clean-up of the HTML obtained. Here is the HTML I retained after cleaning the unwanted elements.

<input type="text" name="Email" id="Email" style="width: 150px" /> 
<input type="password" name="Password" id="Password" style="width: 60px" /> 
<input type="submit" value="Sign in" class="button" />

In the JavaScript function doSubmit() above, you can see that the page is submitted to the URL Now we need to simulate the POST action to be fired on the same URL from our code. For this, I will make the following change to my HTML form tag like this.

<form method="post" action="">

<o:p />

This is a important step to note. With this change, my HTML page will not post to my server, but will post to the URL mentioned in the 'action'. 

My login form will look like this in the browser 

Enter your credentials in this form and click the Sign In button. You will be redirected to and will be logged into the website.

This approach can be used to login into any website which uses a username-password combination for authentication. What you need to login is the HTML source of the login page of the website you need to login and fire the HTTP POST action on the login URL of the destination website. You need to find out where the POST action is fired since the URL of the login page is not necessarily the URL where the POST is fired similar to the one demonstrated here. 

You can download the attached HTML page for a quick demonstration of programmatic logging into . 

Note: I am a member of since the last 6 years and have been answering the quick questions and sometimes posting questions. I am a regular reader of weekly newsletters. But this is my first article on Please let me know your suggestions to improve my article. 


11 Sep 2012- Article submitted to


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Balaji Birajdar (India)
Web Developer
India India
Software developer by profession, working for a service and product based organisation in India.

Career graph:
Software Programmer since 2002.
Web Developer in ASP.NET since 2004.

I love reading the blogs and articles of technology experts. I love codeproject and stackoverflow .

I love to share knowledge and help the programmers. I appreciate if some body corrects my code or my concepts which helps me learn.

You may also be interested in...

Comments and Discussions

QuestionHow about this one? Pin
TYeeTY4-May-13 8:05
memberTYeeTY4-May-13 8:05 
AnswerRe: How about this one? Pin
aspnet_regiis -I4-May-13 8:58
memberaspnet_regiis -I4-May-13 8:58 
GeneralMy vote of 5 Pin
aspnet_regiis -i11-Dec-12 5:31
memberaspnet_regiis -i11-Dec-12 5:31 
Excellelnt tip
QuestionSuggestion Pin
pocky617-Sep-12 0:55
memberpocky617-Sep-12 0:55 
SuggestionThis is not an article. Pin
Slacker00711-Sep-12 5:20
memberSlacker00711-Sep-12 5:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170713.1 | Last Updated 11 Sep 2012
Article Copyright 2012 by Balaji Birajdar (India)
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid