Skip to content

Instantly share code, notes, and snippets.

@ProProgrammer
Last active April 23, 2024 07:38
Show Gist options
  • Save ProProgrammer/8534489 to your computer and use it in GitHub Desktop.
Save ProProgrammer/8534489 to your computer and use it in GitHub Desktop.
A Quick JavaScript written to automate login on a page for testing / fun purpose.
/*
The actual javascript code starts from document.forms[0].username.value.... however to run it in the URL bar (address bar) of a browser you have to put the entire Javascript Code in this format javascript:{<YOUR JAVASCRIPT CODE>}
I have tested it in Chrome, Firefox, Internet Explorer and Safari and it works perfectly fine. If you notice any different behaviour with any other browsers, please test and contribute.
Simply replace <YOUR USER NAME> with your actual username and <YOUR PASSWORD> with your actual login password and run this in browser address bar (no need to input actual URL in the JavaScript code)
------------------------------------------------------------------------------------------------------------
CAUTION: PLEASE ENSURE YOU KEEP YOUR PASSWORD SECURE AS YOU ACTUALLY GIVE YOUR PASSWORD IN TEXT FORMAT INSIDE THIS JAVASCRIPT CODE, SO IF ANYONE GETS ACCESS TO THIS CODE THEY WILL GET ACCESS TO YOUR PASSWORD
------------------------------------------------------------------------------------------------------------
EXPLAINING THE CODE:
documents.forms -- returns an array of all form elements on the page
documents.forms[0] - means first form element in the array of forms
username in documents.forms[0].username.value basically looks at the id of the text input area which is generally kept as 'username' for username area and 'password' for password area
password in documents.forms[0].password.value -- Same as above
.value sets the value of that field as you desire
*/
javascript:{document.forms[0].username.value = '<YOUR USER NAME>'; document.forms[0].password.value = '<YOUR PASSWORD>'; document.forms[0].submit();}
@aemxn
Copy link

aemxn commented Sep 12, 2020

Thanks for your suggestions @ProProgrammer! I'll try it out next time I'm on my computer.

@krjc
Copy link

krjc commented Apr 23, 2024

I'm looking for a way to pay my members tiny amounts into their member accounts, when they login to my site. I hope you can help me either with a script of some sort or, if java script won't do this job, what language will do it?
Thanks for listening. Looking forward to your answer, either way.
Best
Ken.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment