Click here to Skip to main content
15,669,963 members
Articles / Web Development / HTML
Posted 11 Sep 2012

Tagged as


8 bookmarked

Programmatic Login to Website

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
11 Sep 2012CPOL2 min read
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. 


Image 1

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="">


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 

Image 2

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)

Written By
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.

Comments and Discussions

QuestionHow about this one? Pin
TYeeTY4-May-13 8:05
TYeeTY4-May-13 8:05 
AnswerRe: How about this one? Pin
bbirajdar4-May-13 8:58
bbirajdar4-May-13 8:58 
I will test it and will get back to you since you have not provided any other information than the code above.. I suggest you should write some description and post the complete article as an alternative to my tip
GeneralMy vote of 5 Pin
bbirajdar11-Dec-12 5:31
bbirajdar11-Dec-12 5:31 
QuestionSuggestion Pin
pocky617-Sep-12 0:55
pocky617-Sep-12 0:55 
SuggestionThis is not an article. Pin
Slacker00711-Sep-12 5:20
professionalSlacker00711-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.