0

So far, I have a page in my ASP.Net site with 2 partial views, each one with its own form, one for login, and another to register.

They are both working great, except for one thing: If my browser prompts me to remember my password when I log in, the next time I try to login, my Last Name and Password in the Register form is filled with the username/password from the Login form, such as the image below

Here is my problem

Here is the model of the Login and Register

public class RegisterModel : IndexModel
{
    [Required]
    [Display(Name = "Email")]
    [EmailAddress]
    public string Email { get; set; }

    [Required]
    [Display(Name = "First Name")]
    public string FirstName { get; set; }

    [Required]
    [Display(Name = "Last Name")]
    public string LastName { get; set; }

    [Required]
    [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
    [DataType(DataType.Password)]
    [Display(Name = "Password")]
    public string Password { get; set; }

    [DataType(DataType.Password)]
    [Display(Name = "Confirm password")]
    [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
    public string ConfirmPassword { get; set; }
}

public class LoginModel : IndexModel
{
    [Required]
    [Display(Name = "Email")]
    [EmailAddress]
    public string Email { get; set; }

    [Required]
    [DataType(DataType.Password)]
    [Display(Name = "Password")]
    public string Password { get; set; }

    [Display(Name = "Remember me?")]
    public bool RememberMe { get; set; }
}

The login partial

<% using (Html.BeginForm("Login", "Account", FormMethod.Post, new { id = "loginForm" }))
   { %>
    <%: Html.AntiForgeryToken() %>
    <%: Html.ValidationSummary(true) %>
        <div class="12u">
            <span class="input-with-caption fontsize-login">
                <label for="loginEmail"><asp:Literal runat="server" Text="<%$ Resources:LOGIN_EMAIL %>"></asp:Literal></label>
                <%: Html.TextBoxFor(m => m.Email, new {@class = "input-login-contacto redondo", id = "loginEmail"}) %>
            </span>
        </div>
        <div class="12u">
            <span class="input-with-caption fontsize-login">
                <label for="loginPassword"><asp:Literal runat="server" Text="<%$ Resources:LOGIN_PASSWORD %>"></asp:Literal></label>
                <%: Html.PasswordFor(m => m.Password, new {@class = "input-login-contacto redondo", id = "loginPassword"}) %>
            </span>
        </div>
        <div class="12u">
                <p class="remember"><%: Html.CheckBoxFor(m => m.RememberMe) %><asp:Literal runat="server" Text="<%$ Resources:LOGIN_REMEMBER %>"></asp:Literal></p>
        </div>

        <div class="row">
            <div class="5u">
                <input type="submit" name="login" value='<asp:Literal runat="server" Text="<%$ Resources:LOGIN_LOGINBTN %>"></asp:Literal>' class="submit-login-contacto fontsize-login redondo" />
            </div>
<% } %>     
             <%: Html.Action("ExternalLoginsList", "Account", new { ReturnUrl = ViewBag.ReturnUrl }) %>

And here is the Register partial

    <div class="row">
        <div class="6u">
            <div class="12u">
                <span class="input-with-caption fontsize-login">
                    <label for="RegisterFirstName"><asp:Literal runat="server" Text="<%$ Resources:REGISTER_FIRSTNAME %>"></asp:Literal></label>
                    <%: Html.TextBoxFor(m => m.FirstName, new {id = "RegisterFirstName"}) %>
                </span>
            </div>
            <div class="12u">
                <span class="input-with-caption fontsize-login">
                    <label for="RegisterLastName"><asp:Literal runat="server" Text="<%$ Resources:REGISTER_LASTNAME %>"></asp:Literal></label>
                    <%: Html.TextBoxFor(m => m.LastName, new {id = "RegisterLastName"}) %>
                </span>
            </div>
            <div class="12u">
                <span class="input-with-caption fontsize-login">
                    <label for="RegisterPassword"><asp:Literal runat="server" Text="<%$ Resources:REGISTER_PASSWORD %>"></asp:Literal></label>
                    <%: Html.PasswordFor(m => m.Password, new {id = "RegisterPassword"}) %>
                </span>

            </div>
            <div class="12u">
                <span class="input-with-caption fontsize-login">
                    <label for="RegisterConfirmPassword"><asp:Literal runat="server" Text="<%$ Resources:REGISTER_CONFIRMPASS %>"></asp:Literal></label>
                    <%: Html.PasswordFor(m => m.ConfirmPassword, new {id = "RegisterConfirmPassword"}) %>
                </span>

            </div>
        </div>
        <div class="6u">
            <div class="row">
                <div class="12u">
                    <span class="input-with-caption fontsize-login">
                        <label for="RegisterEmail"><asp:Literal runat="server" Text="<%$ Resources:REGISTER_EMAIL %>"></asp:Literal></label>
                        <%: Html.TextBoxFor(m => m.Email, new {id = "RegisterEmail"}) %>
                    </span>
                </div>
                <div class="12u">
                    <%: Html.Captcha(5, "_CaptchaPartial") %>
                </div>

            </div>
        </div> 
    </div>
<% } %>

I've already changed the ids and the names of the inputs, but so far, no success. This is a problem that is happening on Chrome and Firefox (at least, those are the ones that I've tried).

I'm starting to run out of ideas. Any sugestions?

Joao Batista
  • 145
  • 2
  • 7
  • Code would be nice place to start working with your question... There is many option why this is happens. Cookies for one, browser setting second, you getting values from database etc... – All Blond Apr 30 '14 at 17:57

1 Answers1

1

You can annotate your inputs (the ones you don't want the browser to remember) with autocomplete="off"

For example: <%: Html.PasswordFor(m => m.Password, new {id = "RegisterPassword", autocomplete="off"}) %>

http://css-tricks.com/snippets/html/autocomplete-off/

Also, the browser will record the values from the input fields based on their name and then has a set of rules for how to apply them (even on different forms), so if you have the same field names in register and login forms the browser may autofill them: How to trigger Autofill in Google Chrome?

Community
  • 1
  • 1
Rui
  • 4,847
  • 3
  • 29
  • 35
  • Yeah, it worked, after cleaning my cookies :) I can't still figure out the reason why it is assuming that those fields are the same. – Joao Batista May 02 '14 at 10:18