auto login addon /extention.

Posted on 2011-10-14
Last Modified: 2012-06-27
Hello ,

I am looking for a chrome or firefox addon that would take a config file which has website name, user and passwod detials and when every time i enter the website logs me in automatically based on the login credentials dont bother me again and again. I just want to toggle on/ off this perticular addon so it doesnt bother me all the time.
As i see it different website have different login pages and we need to write extention/ add on that caters to the websites that we want to have login automated. Is there an easy way to do this? Watir/ selenium may be... My mind is all over

Please help.

Question by:icylin
    LVL 20

    Expert Comment

    I've done things like this for specific cases and private use:
    One can let the addon check if the current URL belongs to the desired protected site.
    If so, check if the logoin form is shown (a look at the page source will allow you to find suitable criteria for this, e.g. the presence of a form with a spcific id - which is of course site dependant, to say the least)
    Then do some DOM manipulation to replace the <input id="id_of_username_input" type="text" /> with <input id="id_of_username_input" type="hidden" value="the stored username" /> and similarly for the password.
    In my case, I chose not to try to push the login button automatically, but rather change the style of the relevant form elements such that the form with input fields and a small login button gets replaced by a single big login butteon - in other word, pushingthis button is all it takes to login)
    However, for wider use I do not think this is a recommended method.
    For example, you need to store username and password in cleartext or in an easily decodable manner.
    If you want to take this approach in general, this may be quite hard as not every site is so friendly to use a standard form, let alone one that can be recognized by its id.

    Author Comment

    thanks thehagman for your comments.
    I have around 10-15 sites that i need to auto login to and want to get credentials for each site which will be in clear text. Please let me know the easiest way to do it? I am thinking of writing a chrome addon with javascript to insert values into the input elements and push button automatically instead of dom manipulation. But i dont want to get into javascript. Is there any other easy way to get this done?

    LVL 20

    Accepted Solution

    It should be doable (here in FireFox parlance - I'm not sure if your "chrome" refers to the XUL chrome of Firefox or to Google's browser named Chrome):
    Use gBrowser.addEventListener to add a listener to the DOMContentLoaded event
    In the listener, first check whether this is one of the auto login sites, next check if the login form is present (where the id etc. may depend on the site)
    if the form is present, set the values of the corrsponding username and password fields appropriately using document.getElementById('Id of input field').setAttribute("value",yourDesiredInput) and finally call document.getElementById('ID of the submit button').click()
    If some of your sites do not add IDs to all inputs in question, it may be possible to use the array returned from theLoginForm.getElementsByTagName("input") with appropriate indexing. As an inspiration, I myself used essentially  the  code snippet below in my listener routine, which I just adapted slicghtly to meet your requirements

    I'd suggest to place much of the data into configuration (for each site the hostname, form id, username input field if, password input field id, submit button id, user name and password) though it may be easier for a start to put things as constants into the addon in a quick-and-dirty ad-hoc manner

    If this were for a "production system" one should add one more precaution: Just in case you have a typo in user credentials (or did not update the data after a password change), the above methods might cause an infinite loop where the same wrong credentials are tried again and again.

    // site-specific credentials
                 // should of course be filled on a per site basis
                  Merke["name of username field"] = "myusername";
                  Merke["name of password field"] = "T0p_s3cr3t";
                   var Form = doc.getElementById("Form_Login"); // Form_Login happens to be the id of the login form (depends on site)
                    if (Form) {
                            var Inputs = Form.getElementsByTagName("input");
                            var suc = 0;
                            var okbutton = -1;
                            for (var j=0; j<Inputs.length; j++) {
                                    if (Inputs[j].type == "submit") {
                                         okbutton = j;
                                    if ( this.Merke[Inputs[j].name] && this.Merke[Inputs[j].name].length > 0) {
                                            this.Merke[Inputs[j].name] = '';
                            if (suc >1 && ok >= 0) {
                                    // perform action if at least some replacement has taken place
                                    // So this is were the simulated button click should go, I suppose
                                    // I didn't test it, but hope it works

    Open in new window


    Author Comment

    Thanks thehagmam very helpful with your input.. Created below and below logs in but this seem to login over and over again.credentials are right dont know why it does it. Any idea why?

    var href = document.location.href;
    var sitesIndex = [ ['', 'paddypower'],['','gmail'] ];
    var site;
    for ( var i in sitesIndex) {
    	if (href.indexOf(sitesIndex[i][0]) != -1) {
    		site = sitesIndex[i][1];
    if (!site) {
    } else {	
    	function AutoLogin() {
    		this.paddypower = function(){		
    			var evt = document.createEvent("HTMLEvents");
    			evt.initEvent("click", true, true);
    			console.log('paddypower.'+  window.location.href);
    			var uid, passwd, formAnchor;
    			uid = document.getElementById('un');
    			passwd = document.getElementById('pw');
    			formAnchor = document.getElementById('login');
    			if (!uid || !passwd || !formAnchor) {
    				console.log('login form not found');
    			uid.value = username;
    			passwd.value = password;
    		} =function(){
    	var username, password;
    	chrome.extension.sendRequest(site, Autolog)
    	function Autolog(response) {
    	username = response.username;
    	password = response.password;
    	username = (username || '').replace( /^\s+|\s+$/g, '' );
    	password = (password || '').replace( /^\s+|\s+$/g, '' );
    	if (response.enabled == 'false' || username == "" || password == "")
    	var autologin = new AutoLogin();
    	if (!autologin[site]) {
    		console.log('AutoLogin not found for site: ' + site);

    Open in new window


    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    Suggested Solutions

    Do you come here a lot? Are you lazy like me and don't want to go through the "trouble" of having to click your Dock's Safari icon and then having to click your Experts Exchange Favorites bookmark to get here? Well then this article is for you.
    Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
    Google currently has a new report that is in beta and coming soon to Webmaster Tool accounts. This Micro Tutorial will highlight new features for Google Webmaster Tools.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    26 Experts available now in Live!

    Get 1:1 Help Now