<p>I've got quite a few GreaseMonkey scripts that I wrote at my work which automatically log me into the internal sites we have here.  I've managed to write a script for nearly each one of these sites except for our time sheet application, which uses HTTP authentication.  </p>

<p>Is there a way I can use GreaseMonkey to log me into this site automatically?</p>

<p>Edit: I am aware of the store password functionality in browsers, but my scripts go a step further by checking if I'm logged into the site when it loads (by traversing HTML) and then submitting a post to the login page.  This removes the step of having to load up the site, entering the login page, entering my credentials, then hitting submit</p>

[{'answer_id': 49188, 'author': 'Garo Yeriazarian', 'author_id': 2655, 'author_profile': 'https://Stackoverflow.com/users/2655', 'pm_score': 1, 'selected': False, 'text': '<p>Why don\'t you use Firefox (I assume you\'re using Firefox) to remember your credentials using the Password Manager?</p>\n\n<p>I found this link: <a href="http://www.peej.co.uk/articles/http-auth-with-html-forms.html" rel="nofollow noreferrer">HTTP Authentication with HTML Forms</a>.  Looks like you can use javascript to do HTTP authentication.  I don\'t think you can have Greasemonkey interrupt when you are first navigating to a URL though.  You might have to setup some sort of launching point that you can use to have greasemonkey automatically redirect + login.  For example, you can have the local page that takes the destination URL in the query string, have Greasemonkey automatically do the authenticate + redirect.  The only problem is that you\'ll have to wrap the site bookmarks with your launching page for the bookmarks you use as entry points.</p>\n'}, {'answer_id': 49736, 'author': 'pkaeding', 'author_id': 4257, 'author_profile': 'https://Stackoverflow.com/users/4257', 'pm_score': 2, 'selected': False, 'text': "<p>HTTP authentication information is sent on every request, not just to log in.  The browser will cache the login information for the session after you log in the first time.  So, you don't really save anything by trying to check if you are already logged in.</p>\n\n<p>You could also forget about greasemonkey altogether and just give your login into on the url like so:</p>\n\n<pre><code>http://username:password@host/\n</code></pre>\n\n<p>Of course, saving this in a bookmark may be a security risk, but not more-so than saving your password in the browser.</p>\n"}, {'answer_id': 55744, 'author': 'jklp', 'author_id': 3847, 'author_profile': 'https://Stackoverflow.com/users/3847', 'pm_score': 4, 'selected': True, 'text': '<p>It is possible to log in using HTTP authentication by setting the "Authorization" HTTP header, with the value of this header set to the string "basic username:password", but with the "username:password" portion of the string Base 64 encoded.  </p>\n\n<p><a href="http://frontier.userland.com/stories/storyReader$2159" rel="nofollow noreferrer">http://frontier.userland.com/stories/storyReader$2159</a></p>\n\n<p>A bit of researching found that GreaseMonkey has a a function built into it where you can send GET / POST requests to the server called GM_xmlhttpRequest </p>\n\n<p><a href="http://diveintogreasemonkey.org/api/gm_xmlhttprequest.html" rel="nofollow noreferrer">http://diveintogreasemonkey.org/api/gm_xmlhttprequest.html</a></p>\n\n<p>So putting it all together (and also getting this JavaScript code to convert strings into base64 I get the following</p>\n\n<p><a href="http://www.webtoolkit.info/javascript-base64.html" rel="nofollow noreferrer">http://www.webtoolkit.info/javascript-base64.html</a></p>\n\n<pre><code>var loggedInText = document.getElementById(\'metanav\').firstChild.firstChild.innerHTML;\nif (loggedInText != "logged in as jklp") {\n    var username = \'jklp\';\n    var password = \'jklpPass\';\n    var base64string = Base64.encode(username + ":" + password);\n\n    GM_xmlhttpRequest({\n        method: \'GET\',\n        url: \'http://foo.com/trac/login\',\n        headers: {\n            \'User-agent\': \'Mozilla/4.0 (compatible) Greasemonkey/0.3\',\n            \'Accept\': \'application/atom+xml,application/xml,text/xml\',\n            \'Authorization\':\'Basic \' + base64string,\n        }\n    });\n}\n</code></pre>\n\n<p>So when I now visit the site, it traverses the DOM and if I\'m not logged in, it automagically logs me in.  </p>\n'}, {'answer_id': 2070220, 'author': 'Marcin', 'author_id': 251368, 'author_profile': 'https://Stackoverflow.com/users/251368', 'pm_score': 0, 'selected': False, 'text': '<p>"<a href="http://username:password@host/" rel="nofollow noreferrer">http://username:password@host/</a>" doesn\'t work on IE, FireFox works ok.</p>\n'}]
['https://Stackoverflow.com/questions/49158', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3847/']