Saving user name and password
Posted by davidnewcomb on 28 Mar 2014 in Javascript
I have a log in form that requires a user name and password. The form won't remember my passwords because the submission form has autocomplete switched off. Here is an example of a similar form:
<form method="POST" name="loginform" autocomplete="off" action="/cgi-bin/security.cgi"> <input name="un" type="text" /> <input name="pw" type="password" autocomplete="off" /> </form>This means that the person who created the login form has specifically prevented my browser from saving the form user names and passwords. This might be ok in the wild but if you have lots of test systems then it can be a bit of a pain. As my old pal says, "if it's got a chip in it, you can re-program it". This is where I learnt about Bookmarklets.
A bookmarklet is a bookmark stored in a web browser that contains JavaScript commands to extend the browser's functionality.These are very handy for getting around the restrictions build into the D.O.M.. So from the example above we want to switch on the autocomplete for the form and the password field so that the web browser will allow me to save the form data ready for next time. So here is what you do in Firefox but it should work in any browser.
- Right click on the bookmark bar and select New Bookmark.
- Give it a Name, doesn't matter what.
- In the Location enter the following Javascript:
<a href="javascript:(function(){var fm=document.getElementsByTagName('loginform'); var pw=document.getElementsByName('pw'); for(i=0;i<fm.length;i++){fm[i].setAttribute('autocomplete','on');} for(i=0;i<pw.length;i++){pw[i].setAttribute('autocomplete','on');}})()">Autocomplete on</a>
- Click Add.
- Make sure your browser is set up to remember passwords then go to your logging page.
- Click the bookmark in your bookmark bar. This will alter the DOM and switch the auto complete attributes to on.
- Fill in the User Name and Password on the form and click Login.
- Your browser will ask you if you want to remember the credentials, so say that you do.
No feedback yet
Form is loading...