2

How do I prevent my Username and Password ASP.NET/C# TextBox fields from getting pre-populated in Chrome, even if Google Smart Lock has saved it.

I can go into Google settings and delete it, but the next time I login, I get prompted again to save the password for this site. I cannot prevent my other users on this site from saving their passwords when prompted.

I know there are many similar questions to this but none seem to work for me. I have tried (among others):

  1. Setting autocomplete="off" attribute in my TextBox
  2. Setting AutoCompleteType="Disabled" attribute in my TextBox
  3. This: https://stackoverflow.com/a/36904814/4241820

My bank website is able to prevent password from being saved or pre-filled. How is that done?

UPDATE: This is the code from my Login.aspx page:

<%@ Page Title="" Language="C#" MasterPageFile="./MyMasterPage.Master" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="MyApp.Login" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <table style="width: 294px; margin-left: auto; margin-right: auto; margin-top: 80px; margin-bottom: auto; border: none; border-collapse: collapse;">
        <tr style="background-color: #FFFFFF;">
            <td style="text-align: center;">
                <br />
                <img src="Images/AppLogo.png" alt="Application Logo" />
            </td>
        </tr>
        <tr>
            <td style="background-color: #FFFFFF; text-align: center;">
                <asp:PlaceHolder runat="server" ID="LoginStatus" Visible="false">
                    <p>
                        <asp:Label ID="lblStatus" CssClass="lblSkin" runat="server" />
                    </p>
                </asp:PlaceHolder>
                <asp:PlaceHolder runat="server" ID="LoginForm" Visible="false">
                    <br />
                    <asp:Label ID="lblTitle" CssClass="lblSkinLarge" runat="server" /><br />
                    <br />
                    <div style="margin-bottom: 10px">
                        <input style="display: none" type="text" name="fakeusername" />
                        <asp:Label Text="Username" CssClass="lblSkin" AssociatedControlID="UserName" runat="server" /><br />
                        <asp:TextBox runat="server" ID="UserName" Width="244px" autocomplete="off" AutoCompleteType="Disabled" />
                    </div>
                    <div style="margin-bottom: 10px">
                        <input style="display: none" type="password" name="fakepassword" />
                        <asp:Label Text="Password" AssociatedControlID="Password" CssClass="lblSkin" runat="server" /><br />
                        <asp:TextBox runat="server" ID="Password" TextMode="Password" Width="244px" autocomplete="off" />
                    </div>
                    <div style="margin-bottom: 10px">
                        <div>
                            <asp:ImageButton AlternateText="Login" ImageUrl="~/Images/btnLogin.jpg" OnClick="SignIn" runat="server" />
                            <br />
                            <asp:HyperLink ID="lnkForgotPassword" CssClass="lblSkin" NavigateUrl="Login_ResetPassword.aspx" Text="Forgot password" runat="server" />
                        </div>
                    </div>
                </asp:PlaceHolder>
                <asp:PlaceHolder runat="server" ID="LogoutButton" Visible="false">
                    <div>
                        <div>
                            <asp:Button runat="server" OnClick="SignOut" Text="Log out" />
                        </div>
                    </div>
                </asp:PlaceHolder>
            </td>
        </tr>
    </table>
</asp:Content>
Community
  • 1
  • 1
Windhoek
  • 1,701
  • 1
  • 15
  • 26

2 Answers2

3

Don't set autocomplete="off" on text box but on the form where it is placed.

<form id="form1" runat="server" autocomplete="off">

Imad
  • 7,126
  • 12
  • 55
  • 112
  • Thanks for your reply. I added autocomplete="off" to the "form" in the master page (which encloses the textbox). But when I load the page, the pre-filled username still appears. – Windhoek Apr 17 '17 at 08:01
  • @Windhoek I don't know why it still appears but one suggestion, don't use same master page for login and other pages. It's problamatic if you are doing auth related stuff as a common accross app in master page. – Imad Apr 17 '17 at 08:44
  • That does not solve the issue. He wanted to turn off autocompletion for one field nad not for the entire form. – dave0688 Jun 12 '20 at 09:27
1

We got the same situation like this but i followed following approach to overcome this situation

In the New page inside your Mark Up before your txtInsuredPassword try to keep this input type so that your problem will be solved

   <input style="display: none" type="text" name="fakeusername" />
  <input style="display: none" type="password" name="fakepassword" />

Try to keep this marup above your actual username and password

Krsna Kishore
  • 8,233
  • 4
  • 32
  • 48