Many of us visits few particular sites many times a day. When you login to your system and open the browser, the first sites most of us hit is google.com right. Then there are few specific sites user want them to be available in their different tabs. We close the browser many times & open it and do the same thing again and again.
It becomes a pause in our flow to do the same thing repeatedly and more frustrating sometimes when the sites require your credentials to login. If your hangs while opening it turns out more ugly.

Here, in this article we will discuss how to automate it, so that with just a single click you get your browser opened with all the required webpages auto login.

Our aim here is to script which opens your browser then open the websites in different tabs for you.

Lets consider an example where we
want to open these sites.

1) http://www.timesofindia.indiatimes.com
2) www.weebly.com

Step 1. Create a batch script to open Browser with specified webpage.

Well that's pretty simple. we just have to write the command like this start firefox.exe google.com
this will open your firefox browser and open google.com as your first tab.

We will do this step in the end, I will explain you why.

Step 2. Make Websites to login automatically.

If you are familiar with web-pages you would be knowing that how posting data in web page works. If you are not aware no need to worry as we don't require in-depth details of it.
A web-page (.html or .htm) has a form element, this form element captures your details like username & password and the form has action attribute which defines to which location the form should be sent when user hits submit.
Examples of form is below

<form action="http://mywebsite.com/login" method="post">
  Username: <input name="user"><br>
  Password: <input name="pwd"><br>
  <input value="Submit">
</form>

<form action="login.jsp" method="post">
  Username: <input name="user"><br>
  Password: <input name="pwd"><br>
  <input value="Submit">
</form>

Note the difference between two forms. In the first form the action is complete url while in second it is not. In second it is a relative url. For our processing, we will be needing the complete url, if the webpage uses relative form action path you can make it complete url like this

if your login page address is
http://mywebsite.com and form action is given as login.jsp
then complete url would be
http://mywebsite.com/login.jsp

Now as you can understand the main part we are concerned about is form element of webpage.

To auto login we can achieve this via two ways.

a. Save the login page and edit the value of username and password in the respective form elements.

b.
Create a new web page and copy the form elements in to it.

We will take both the approach one by one.

Consider the first case
where we will save the page and edit it according to our needs.

www.weebly.com this is the page we want it to login automatically.


Do the following steps.

a.1 Open Browser and hit the url www.weebly.com, once the page is loaded save the page (Ctrl + s)

a.2 Open the saved htm file in notepad or notepad++
a.3 Place the mouse at the top row and search for "Email Or Username" as displayed in the webpage.
a.4 When you find the matching text, try to find the form element containing this.

Snapshots available below are not in proper sequence. Sorry for being lazy :-)
a.5 If we look the action url of the form it is a complete url. So we don't need to modify it.
a.6 Now we have to hardcode the Username & Password in the form. for this we need to add the value tag with       the corresponding value of Username & Password.
a.7 We will name our form as something so that we can submit it by name. use name="auto_submit_form"
a.8 To auto submit the form we need to write a small script.
      <script type="text/javascript">
        document.forms["auto_submit_form"].submit();
    </script>

This Script must be added just before the body closing tag. </body>

Now after doing all this modifications, save your html file and open in the browser. it should logged in automatically if everything was done as told.

Now we will look on another way of achieving this.

As we progressed, we saw that the only thing that matters are form data. so if we can keep that form data and remove everything it will look simple enough to grasp.

Look at this HTML file..


<html>
    <body>
        <form name="auto_submit_form" id="weebly-login" method="post"
                        action="https://www.weebly.com/weebly/login.php">
            <input  id="weebly-username"  name="user" value="[email protected]"
                    placeholder="Email or Username" ><br>

            <input id="weebly-password"  name="pass" value="myPassword" placeholder="Password" ><br>
            <input name="force-submit" id="force-submit" value="0" >
</form>

    <script >
        document.forms["auto_submit_form"].submit();
    </script>   

</body>
</html>


It conveys the same thing as of that webpage we downloaded. Except there is no fancy UI available. But we don't want it too as our aim is to go to Home page directly, crossing the login page.
If you save the above code as filename.htm and run it in browser it will result in the same thing.


We have achieved the login functionality as of now. Now we just have to connect everything together.

Save the modified page either by approach a or b and place it in a directory.
Lets assume the directory is C:\Documents and Settings\user1\Desktop\blogs_stuff and filename is weebly.htm


Now open a
blank file paste the below code and save it as .bat file.

start firefox.exe "
C:\Documents and Settings\user1\Desktop\blogs_stuff\weebly.htm"
ping -w 2000 0.0.0.0
start firefox.exe "timesofindia.com"


The code looks pretty simple we command to open firefox with the mentioned URL.

What's the use of
ping -w 2000 0.0.0.0
It commands to ping to ip address 0.0.0.0 with timeout as 2000 milli seconds. As ip 0.0.0.0 is invalid we are expecting a timeout to happen that can give us a break of 2 sec.

This line helps us to give a pause for 2 sec before opening
timesofindia.com, If we don't do so, The execution will happen so fast that it will end up opening two browser windows.

Note: This is tested just for firefox, running in iexplorer may behave weirdly & you will be required to do some tweaks.


That's it, we are done with our work. But remember that this has major security breech, Your password is available in a file and anyone can read it & misuse it. So be careful while doing it. :-)

Let me know if you have any doubts. Have a nice day :-)

*****************************************************************************************************************************************
4/2/2016 04:30:31 am

I may have caught them at a bad time, but the rating stands until I go again or get new pics to judge from.

Reply



Leave a Reply.