By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,466 Members | 1,138 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,466 IT Pros & Developers. It's quick & easy.

Autofill user name and password

P: 7

I have a situation where I have to share user names and passwords for a list of sites among several (30 or so) users. These passwords must be reset every 90 days and anytime any one of the users is no longer employed by us. As you can imagine, the user will get locked frequently due to people not paying attention to when a password changes.

I want to create a web site that has a link to each site that when clicked will take you to the site and auto fill the user name and password.

I am attempting to do this using bookmarklets. This is what I have so far:

Expand|Select|Wrap|Line Numbers
  1. javascript:window.location.href ="";
  2. checkLoad();
  4. function checkLoad()
  5. {
  6. if (window.onLoad)
  7. {document.forms[0].elements["oper"].value ='Eric';document.forms[0].elements["pswd"].value = 'secret';} 
  8. else {setTimeout('checkLoad()',1000);}}
Obviously, I replaced with the site I was trying to log into.

I know the second bit works (the document.forms... part) because if I navigate to the page and then execute it, it will fill in the fields. However, when I run it as is, it takes me to the page but does not fill in the fields.

The function checkLoad is supposed to check if the page is loaded and fill in the fields when it is, but it isn't working. Any suggestions or alternative approaches would be very welcome
Dec 2 '09 #1
Share this Question
Share on Google+
15 Replies

Expert Mod 5K+
P: 8,639
postpone the call until the page finished loading, meaning use the onload event.
Expand|Select|Wrap|Line Numbers
  1. window.onload = function() {
  2.     // execute code here
  3. }
  4. // or
  5. window.onload = fn_call;
Dec 2 '09 #2

P: 7
I tried this:

Expand|Select|Wrap|Line Numbers
  1. javascript:window.location.href ="";window.onload = document.forms[0].elements["oper"].value ='Eric';document.forms[0].elements["pswd"].value = 'secret';
No luck, it navigates to the page but does not fill out the fields. Any ideas as to why not?
Dec 2 '09 #3

Expert Mod 5K+
P: 8,639
Any ideas as to why not?
sure, the syntax is wrong. every event handler ecpects a function to be passed.

Expand|Select|Wrap|Line Numbers
  1. function doSomething()
  2. {
  3.     // some code
  4. }
  5. window.onload = doSomething;
Dec 2 '09 #4

P: 7
OK - I think I'm not getting it. Here's what I've got:

Expand|Select|Wrap|Line Numbers
  1. javascript:window.location.href ="";
  2. window.onload = PreFill();
  3. function PreFill()
  4. {
  5. document.forms[0].elements["oper"].value ='Eric';
  6. document.forms[0].elements["pswd"].value = 'secret';
  7. }
If I execute this from a different website, it will take me to the desired website but will not fill in the form.

If I execute it from the website I'm trying to go to, it will briefly fill out the name and password fields but then reload the site and remove the info from these fields. Its as if it is not waiting until the site is loaded to run the function PreFill().
Dec 2 '09 #5

Expert Mod 5K+
P: 8,639
the syntax on line 2 is still incorrect, see example above.
Dec 2 '09 #6

P: 7
Sorry, but I am still not getting what is wrong with line 2. I tried putting the function call after the function definition, like so:
Expand|Select|Wrap|Line Numbers
  1.  javascript:window.location.href ="";
  2.  function PreFill()
  3.  {
  4.  document.forms[0].elements["oper"].value ='Eric';
  5.  document.forms[0].elements["pswd"].value = 'secret';
  6.  };
  7.  window.onload = PreFill();
but got the same result - it would take me to the page but not prefill anything. I am running this like a bookmarklet - is that the problem? Is there another way I could run it?
Dec 2 '09 #7

Expert Mod 5K+
P: 8,639
Expand|Select|Wrap|Line Numbers
  1. window.onload = doSomething;
Expand|Select|Wrap|Line Numbers
  1. window.onload = PreFill();
whatís the difference?
Dec 2 '09 #8

P: 7
The difference is the name of the function and the fact that I have parenthesis and you do not. When I remove the parenthesis, the same thing happens - the page opens, but the fields are not pre loaded. If I rename the function, that does not work either.
Dec 2 '09 #9

Expert Mod 5K+
P: 8,639
anyways, putting the parentheses there is simply wrong (for a certain reason).

Iíll do some testing to reproduce the error.
Dec 2 '09 #10

Expert Mod 5K+
P: 8,639
after following some links I found that the bookmarklets are treated like links, thus the use of the void() function seems favourable. further investigation to follow.

personally I doubt, that you can execute code after you load another page.

if I try to jump to another page and then execute code, I’m prompted with an XSS warning. no point in trying this approach further.

however, you may use the bookmarklet on your page after you load the page via regular bookmark. this certainly worked.
Dec 2 '09 #11

P: 7
Thanks for your help on this so far.

If a bookmarklet won't work, do you have any other ideas as to how I can approach this? My goal is to have a page that would list all sites that we use a shared password for. When you clicked on the site, it would take you to the site and enter your credentials. Thanks again!
Dec 3 '09 #12

Expert Mod 5K+
P: 8,639
When you clicked on the site, it would take you to the site and enter your credentials.
my browser handles those for me, no need to use anything else.
Dec 3 '09 #13

P: 7
Yes, and that is part of the issue. Given that the credentials are shared among several users, and need to be changed every 90 days, we run into problems where the stored credentials become invalid. The user tries multiple times and ends up locking the account, which then needs to be unlocked.

The idea here is that if they used the link I want to create, they would always be using the correct credentials.
Dec 3 '09 #14

Expert Mod 15k+
P: 16,027
One possibility is:
Expand|Select|Wrap|Line Numbers
  1. javascript:window.location.href ="";
though you'd have to change the code in the page to take the input parameters and set the username/password.

However, I would advise that whenever the user names and passwords are changed, display a message on the login page to inform the user that the password has changed, so they will know that they need to enter a new password.

Of course, users don't always follow instructions, so one more thing you could look at is to store the old password too, then if that is entered, post a friendly reminder that the password has now changed.

Just some ideas you could look into.
Dec 7 '09 #15

P: 15
How about having the browser store the all passwords to autofill like normal and then re-writing the browser's datafile with external software to change the passwords?

If it's FireFox you may even be able to just get it to output a text file that you can change and email to all the user's to install?

How do you change the passwords on the many sites?
Dec 8 '09 #16

Post your reply

Sign in to post your reply or Sign up for a free account.