2

I need to prevent the storing of username/password on my MVC 5 site.

I have set the both the form and input elements to autocomplete="off" and I'm sure the site is running HTML5. For all intents and purposes it should not want to store the login information, yet, it still prompts for it after login.

As suggested, I tried changing the input field names to something other than "username" and "password", but it changed nothing.

I have even tried the trick of adding dummy username & password hidden elements outside the form, tried inside the form as well. No joy.

I have also tried doing it in jQuery, with no success

$("input").attr("autocomplete", "off");

Form tag:

<form action="/" autocomplete="off" class="form-horizontal" method="post" role="form" novalidate="novalidate">

input element:

<input autocomplete="off" class="form-control" data-val="true" data-val-regex="Mobile number must be a Numbers only." data-val-regex-pattern="[0-9]*\.?[0-9]+" data-val-required="The Mobile field is required." id="Username" name="Username" type="text" value="">

Tested in IE and chrome, but prompt to save info.

Any help or advice would be greatly appreciated. How do banks prevent this?

Swifty
  • 1,282
  • 2
  • 16
  • 35
  • Is your question related to browser preserving password in the form fields? – ramiramilu Jun 12 '15 at 08:05
  • @ramiramilu Yes, I don't want the login credentials to be saved. Supposedly, with HTML5 you can specify autocomplete=off to signal to the browser that is should not store the info, yet its not working. – Swifty Jun 12 '15 at 08:09
  • Possible Duplicate of - http://stackoverflow.com/questions/2530/how-do-you-disable-browser-autocomplete-on-web-form-field-input-tag – ramiramilu Jun 12 '15 at 08:16
  • No it is not a dupe, I specifically state that I have done all that is suggested in the plethora of similar posts out there, yet none of the proposed solutions are working for me. – Swifty Jun 12 '15 at 08:37
  • If it's the browser preserving the value it may be the browser sees a field called Username and thinks you are storing user credentials so should get them from the built in password manager. Maybe rename the field (if you can) to something else? – Nigel Ellis Jun 12 '15 at 09:18
  • @NigelEllis I tried that too, no joy. I still get asked to save details. How do banking sites prevent this? – Swifty Jun 12 '15 at 11:05
  • @Swifty Can't answer that one. I've just checked my online bank and they just have autocomplete="off" in the form and the input tag (which is called "frmLogin:strCustomerLogin_userID"). – Nigel Ellis Jun 12 '15 at 11:23

1 Answers1

1

I tested many solution and finally, came with this one.

HTML code

@Html.TextBoxFor(m => m.UserName, new { @class = "form-control", @placeholder = "UserName", @autofocus = "", @autocomplete = "off" })

@Html.TextBoxFor(m => m.Password, new { @class = "form-control", @placeholder = "Password", @autocomplete = "off" })

CSS code

#Password {
    text-security: disc;
    -webkit-text-security: disc;
    -moz-text-security: disc;
}

JavaScript code

window.onload = function () {
    init();
}

function init() {
    var x = document.getElementsByTagName("input")["Password"];
    var style = window.getComputedStyle(x);
    console.log(style);

    if (style.webkitTextSecurity) {
        // Do nothing
    } else {
        x.setAttribute("type", "password");
    }
}
β.εηοιτ.βε
  • 16,236
  • 11
  • 41
  • 53
Haniyeh
  • 41
  • 1