1

I'm trying to disable the browser autocomplete on my Login form only after the user is being redirected from the reset password page.

I read many answers in SO but couldn't find something that worked for me.

I tried to set autocomplete="off" on the form tag, on each input but it didn't work.

I tried adding hidden fields as many suggested but it only works if I set on the fake password field the same name of the real password field - what of course I can't do.

That's the only way I got it to work:

<form id="login-form" method="post" action="/account/login">
    <!-- fake fields are a workaround for chrome autofill getting the wrong fields -->
    <input type="text" name="prevent_autofill" id="prevent_autofill" value="" style="display:none;" />
    <input type="password" name="password" id="password_fake" value="" style="display:none;" />
    <!-- ------- -->
    <div class="inputField resetPasswordLogin login">
        <input type="email" id="email" name="email" placeholder="USERNAME"/>
    </div>
    <div class="inputField resetPasswordLogin login">
        <input type="password" id="password" name="password" placeholder="PASSWORD"/>
        <input type="submit" class="hiddenSubmit" id="hiddenLogin"/>
    </div>
</form>

It seems like this workaround works without having to set the same name in the password filed, any idea what can causes such a behavior?

user3378165
  • 5,189
  • 15
  • 49
  • 86
  • 1
    Possible duplicate of [How do you disable browser Autocomplete on web form field / input tag?](https://stackoverflow.com/questions/2530/how-do-you-disable-browser-autocomplete-on-web-form-field-input-tag) – Obsidian Age Jan 18 '18 at 21:04
  • @ObsidianAge Thank you, but I read this question many times and I specified in my question why it is different than this question. I read a few times the 49 answers there but it doesn't answer my question so I'll appreciate if you remove the duplicate. – user3378165 Jan 18 '18 at 21:14
  • You ask how to disable autocompletion on a login form, and none of the 49 different answers on how to disable autocompletion for the `
    ` and `` tags answered your question? To disable it "*only after the user is being redirected from the reset password page*" you would need conditional JavaScript to dynamically update the form to include `autocomplete="off"` when `document.referrer` is the relevant page.
    – Obsidian Age Jan 18 '18 at 21:32
  • @ObsidianAge My question wasn't about how to disable it _"only after the user is being redirected from the reset password page"_ my question is asking how I can disable the autocomplete **without having to specify the same name in the fake password field as the real password field** and yes, I didn't find something similar in all 49 answers. – user3378165 Jan 18 '18 at 21:39

1 Answers1

1

This is what finally worked for me:

<div style="height:0px; overflow:hidden; ">
  Username <input type="text" name="fake_username" >
  Password <input type="password" name="fake_password">
</div>
user3378165
  • 5,189
  • 15
  • 49
  • 86