Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Disable login form autocomplete

jcwebdevjcwebdev New
edited June 2012 in Vanilla 2.0 - 2.8

I'd like to disable autocomplete on my login forms. Is there any straightforward way of doing this?

Thanks

John

Tagged:

Answers

  • I used jquery and a simple hook in Wordpress. How can it be done in Vanilla?

  • 422422 Developer MVP

    Add autocomplete="off" to input element

    There was an error rendering this rich post.

  • I'd rather not have to modify Vanilla core. I've figured out how to load jQuery from Google in my theme by hooking it into the head. How would I go about loading a custom script?

  • I was able to get my script to load using this piece of code:

    public function Base_Render_Before(&$Sender) { $AutocompleteOff = ' <script type="text/javascript"> $(document).ready(function() {$(\'input\').attr(\'autocomplete\',\'off\');}); </script>'; $Sender->Head->AddString($AutocompleteOff);

    That said, when the users clicks 'Sign In', the sign in form is dynamically loaded so I'm not sure if my piece of JS will work.

  • Come on folks! How would I do this without modifying the core?

  • peregrineperegrine MVP
    edited June 2012

    there may be a better way. but this works.

    noauto.js

        jQuery(document).ready(function($) {
        $("input").livequery( function()
        $("#Form_Email").attr("autocomplete","off"));
        }); 
    

    create your own plugin and add something with this. or add something to your themehooks.

    public function Base_Render_Before($Sender) {
        $Sender->AddJsFile('/plugins/thenameofyourplugin/js/noauto.js');
    

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Ok...got the script to load but it isn't adding this attribute to my inputs. Could it be that this is due to the login form being loaded by javascript after the page itself loads?

  • the livequery theoretically "lives on" even thought the form loads later.. do you have a link to your page and can you explain exactly what you did? if you want some help debugging.

    aside from the autocomplete issue itself.

    first see if the script works.

    cut and paste it in your console and run it and bring up the signin box.

    For a test I just modified the addmenu item plugin added the function and the js and it worked on my browser.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • peregrineperegrine MVP
    edited June 2012

    the script above will only add the attribute to
    #Form_Email"- which is what you requested not all inputs.

    why don't you turn off autocomplete in your browser. Maybe other users would like an autocomplete.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • I'm still stuck on this one. I need to disable autocomplete on all logins as my client has specifically requested it. The idea is that many of the site's users aren't particularly gifted technically and could well sign in and forget to sign out or leave their computer unattended.

    The sites are currently inaccessible to anyone outside my client's VLAN so I can't provide you with the URL to help with debugging.

    I can get an alert to display if I add it to the function but I cannot get the js function to add autocomplete=off to my inputs...where could I be going wrong? It must be the selector surely?

  • I no longer need this. I'm using jsConnect for single sign on and have removed all links to the default register/sign in pages.

    No users should be using them this way so there should be no data to autocomplete.

    Thanks for your help peregrine!

  • I did end up needing this, I created a custom plugin and disabled autocomplete on my login forms using this:

    class CustomJSPlugin extends Gdn_Plugin {
    public function Base_Render_Before(&$Sender)
    {
    $JavaScript = '

    $(document).ready(function() { $("#Form_User_SignIn input").attr("autocomplete","off"); });

    ';
    // Send it to the Header of the page
    $Sender->Head->AddString($JavaScript);
    }
    }

    Hope it helps someone!

Sign In or Register to comment.