Link to home
Start Free TrialLog in
Avatar of E=mc2
E=mc2Flag for Canada

asked on

Automatic login to a browser with username and password

Using a script or some other method, or shortcut, I would like to access a specific website, which then enters the username and password automatically, without having the need for a user to input the username and password.
This would be used for frequently visited sites....
Thank you.
Avatar of Sam Jacobs
Sam Jacobs
Flag of United States of America image

Are these internal or external sites?
You would need to know the HTML IDs of the name and password fields on each site.
Even with the above, the script can get tripped up if, for example, a browser warning pops up, or some other unexpected dialog box.
Avatar of E=mc2

ASKER

These are external sites.
Best to use a system like LastPass to manage your passwords for you.

Managing the login process for many sites can be far more complex than might be imagined, because of all the Javascript running on sites these days.
@100questions - While I myself use a PowerShell script to access and log on to certain sites (and could send you a sample if you send me one of the sites you are trying to access), I agree with David about the complexity. I also use LastPass to manage my passwords.
Avatar of E=mc2

ASKER

Thanks to all.  Where does LastPass store the passwords?
Also, I would like to see the PowerShell script if you do have it, that would truly help.
I am looking at using Auto Hot Key to help me with this, however the issue is that the ID is the same for both the Username and Password fields.  I believe the site I want to use does have JavaScript.
Will wait for the powershell script.
If you want to write code in c/c++/c# to achieve this, then can use IWebBrowser2 interface.
OK ... please see the attached, and make sure to modify the 3 variables at the top of the script (URL, username, and location to securely store your credentials).

Important notes:
This script will only work if your credentials are correct ... it will not retry.
Please run this script with IE closed.

Please let me know if you have any questions.
webLogin.ps1
Avatar of E=mc2

ASKER

Thanks Sam, however the script does not work.. but thanks very much for your help much appreciated.
When I run it, I can see the fields being filled in and the login button is clicked.
I receive a message that the credentials are not valid (because they aren't).
What is happening when you run it?
Here's the thing about writing scripts to do logins.

The only real way to do this is to use http://phantomjs.org/ which is a headless/screenless version of Chrome.

PhantomJS runs all HTML + CSS + Javascript, so you actually can interact with sites as if you were running a browser.

Also keep in mind, when you login...

1) This does mean you're logged in + your PhantomJS login correctly maintains session/cookie data.

2) This does not me you can somehow login with PhantomJS or any other similar tool, then somehow be logged in for some other context. In other words, you can't somehow login with a script + then access a site using some other script of browser. Session/Cookie data pins to however you do your login.

3) You can login with PhantomJS passing a known cookie file path, then use the login cookie path in another tool like curl, then use PhantomJS to logout passing the login cookie path.

This is fairly common...

Search http://phantomjs.org/examples for many examples. Also search places like GitHub for working code fragments.
If you are using Microsoft Edge or Internet Explorer(I know it is rare but still many are using them), you can use built-in Windows Credentials Manager.

Here are the steps to use it: https://www.howto-connect.com/how-to-use-credential-manager-windows-10/
To extend Chinmay's point, why not use your browser's built-in password manager? As long as you don't enable profile syncing, your passwords are stored locally.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.