Problem

  1. When creating a user account on a Drupal site, then the built-in login form autocompletion (password manager) feature of web browsers (at least Firefox) identifies the email field as the username (instead of the username field).
  2. If I let my browser/password-manager save my credentials, then a wrong username is stored and I cannot log in with the saved credentials.

Cause

  1. Built-in detection of login fields in forms is a best guess of web browsers, not an official HTML standard (nor a feature of the "autocomplete" attribute).
  2. The email field appears directly before the password field. → The email field is identified as the username field.

Goal

  • As an end-user who creates a user account on a Drupal site (and who is using a password manager), I want my browser to correctly identify my user credentials, so I can save them and use them the next time I need to log in.

Security

  1. Several security articles on the net advise web site owners to disable the autocomplete functionality for user registration/login forms. — Even though they are just pointing out weaknesses in individual browsers that simply ought to be fixed by the respective browser vendors.
  2. The trumping counter-argument is that force-disabling password managers encourages bad practices (using a similar password on multiple websites, writing it down or typing it into an insecure document, etc).
  3. Drupal core did not care for any of these security concerns in the past.

    → The only purpose of this issue is to ensure that a password manager works correctly, if the user chooses to use one (which is not something Drupal should decide in the first place).

Proposed solution

  1. Change the order of the username and email fields in the user account registration/creation form, so that the username field appears before the password field and is correctly identified by password managers:

    Username field is correctly identified

Screenshots

→ The order of the Username and E-mail fields is swapped, so that the Username field appears right above the password element:

 Maintenance account form

User registration form

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sun’s picture

Issue summary: View changes
FileSize
59.58 KB
dawehner’s picture

Priority: Normal » Major

Given that this affects quite a lot of users (everyone using a browser) I would argue that this is major.

larowlan’s picture

Sad that we can't use form display mode settings here to put the decision in hands of site builder

sun’s picture

Issue summary: View changes

I wonder what else is actually needed for this issue?

I considered to perhaps add an assertion to an existing user registration test, so as to ensure that the order of fields is not changed/broken in the future, but then again, I'm not sure whether that is really necessary?

Lastly, please note that this patch essentially reverts parts the patch of #1525640: Disable autocompletion for email/password field when editing user profile, because that issue seemingly just worked around the actual root cause (as outlined here).

Berdir’s picture

The main problem there IMHO was editing an account of *someone else*, where it also auto completed it with your own information and overwrites the existing. Needs to be confirmed how that exactly behaves now with your changes...

sun’s picture

editing an account of *someone else*, where it also auto completed it with your own information and overwrites the existing.

I'm afraid I'm not able to follow. — The browser's autocomplete + password manager behavior only kicks in for empty form input fields.

→ When editing an existing user account, then the user name + email fields already contain values. No autocompletion.

I can happily add some extra code to add an autocomplete="off" attribute when $account->id() > 0, but I honestly don't see the point of that. ;-)

sun’s picture

Issue tags: +Needs usability review
sun’s picture

Re-rolled against HEAD.

sun’s picture

sun’s picture

Issue summary: View changes
FileSize
116.75 KB
41.89 KB

As an attempt to move this issue forward, here are two screenshots of the two forms that are primarily affected by this change.

→ The order of the Username and E-mail fields is swapped, so that the Username field appears right above the password element.

sun’s picture

sun’s picture

tstoeckler’s picture

Haven't experienced the problem reported in #5 either. The problem this issue fixes is a pain, however, and has been bugging me for a while. Code-wise it's RTBC, but I suppose we need some more opinions before this can go in?!

sun’s picture

sun’s picture

I think I've provided everything that I can to make reviews of this change as easy as possible.

Thus far, I've the impression that no one raised objections to swapping the two input fields. Shall we move forward here?

If people think it is necessary, I'm also happy to add a quick test assertion for this somewhere; thus far, I merely thought that might be overkill.

sun’s picture

Issue tags: +Sunrise Sanity Cruise
sun’s picture

What can I do to move this forward?

mgifford’s picture

This patch still applies nicely on SimplyTest.me

So what are the simplest steps to replicate this problem. The goal of the code is just to re-order the form so that the browser makes a better choice about what to remember, right?

1) Spin up a new instance.
2) Create a new account & verify that your browser has "Remembered" them.
3) Look in your browser, look at the security preferences & verify that the saved password is under the username and not the email address.

Would be nice to get this fixed up.

sun’s picture

FileSize
7.64 KB
3.45 KB

Added test coverage.

sun’s picture

19: user.form_.19.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 19: user.form_.19.patch, failed testing.

sun’s picture

Status: Needs work » Needs review
FileSize
7.63 KB
739 bytes

Updated for EntityManager::getStorageController() renamed to getStorage().

sun’s picture

22: user.form_.22.patch queued for re-testing.

Bojhan’s picture

Issue tags: -Needs usability review

This looks like a very good idea, I expect few to no usability issues will arise from this.

sun’s picture

FileSize
9.99 KB
6.66 KB

Add autocomplete=off if operation is not 'register' + added test coverage.

This (hopefully final) patch adds proper test coverage for the changes performed in the following issues (which should have added test coverage on their own):

#1525640: Disable autocompletion for email/password field when editing user profile
#787876: Edit "My Account" fills the first password field
#2219443: Autocomplete in Safari 7 overwrites email address on user profile edit form

The revised test not only asserts the field order, but additionally asserts the expected appearance of the autocomplete=off attribute on both the user registration and the user edit/profile form (as well as the maintenance user account form in the installer).

sun’s picture

25: user.form_.25.patch queued for re-testing.

sun’s picture

25: user.form_.25.patch queued for re-testing.

sun’s picture

What can I do that allows us to move forward here?

mgifford’s picture

A clear testing process for this patch (#18?), someone to review the code and someone to mark it RTBC.

Think that's all.

sun’s picture

Yup, the procedure in #18 is accurate.

Anonymous’s picture

Issue tags: +Needs reroll

I started reviewing this and can confirm that my email address was stored instead of my username.
Then I wanted to test the patch, but it doesn't apply anymore. Tagging this for a reroll.

sun’s picture

Issue tags: -Needs reroll
FileSize
10.1 KB
1.46 KB

Resolved merge conflicts.

Status: Needs review » Needs work

The last submitted patch, 32: user.form_.32.patch, failed testing.

sun’s picture

Status: Needs work » Needs review
FileSize
10.13 KB
872 bytes

Updated UserAccountFormFieldsTest for modernized installer forms.

sun’s picture

34: user.form_.34.patch queued for re-testing.

Status: Needs review » Needs work

The last submitted patch, 34: user.form_.34.patch, failed testing.

sun’s picture

Status: Needs work » Needs review
FileSize
10.09 KB

Merged HEAD

Status: Needs review » Needs work

The last submitted patch, 37: user.form_.37.patch, failed testing.

sun’s picture

Status: Needs work » Needs review
FileSize
10.08 KB
1.08 KB
Anonymous’s picture

Codewise this seems ok and the patch works as expected. The username is saved instead of the email address, and thus the autofill works right.

I wasn't able to reproduce the issue as described in #5.

However, after playing around with this, I found another case where the change could be needed:
- register a new account and save the credentials
- logout
- login as an admin
- add a new user

The credentials that are stored while registering for an account are filled in here. I would think that, similar to the user edit form, autocomplete should be set explicitely to "off" here as well.

sun’s picture

re: #40: @pjonckiere:

Hm. I started to look into that, but then I questioned whether that expectation is actually universally true.

The counter-expectation would be:

  1. Log in as admin.
  2. (Administratively) Create a new user account.
  3. Log out.
  4. Log in as that new user account using your password manager.

These are two conflicting expectations. (In fact, that's how I generated some of the screenshots in the OP.)

It additionally depends on the password manager's behavior whether the form fields on the user creation form are automatically filled out or not. Some password managers always require you to use autocomplete or click a button to fill in your credentials. And of course, if multiple credentials are stored, then you always need to choose one.

Since no clear/sane/universal expectation can be made, I'd rather leave the administrative user creation form alone; i.e., deferring the choice to users/agents.

Thoughts?

Anonymous’s picture

Status: Needs review » Active

An argument could be that an admin will use the "add a user" functionality more often to create new accounts for other people and not for him-/herself. But I can agree that there is no solution that will satisfy all use cases, and for that reason I think it's reasonable to leave the form as-is.

Since the initial problem (storage of email iso user) is resolved and the test coverage seems sufficient, I think this patch is good to go.

sun’s picture

Status: Active » Reviewed & tested by the community

I think this patch is good to go.

I guess you meant this status then ;-)

sun’s picture

Title: Browser login form autocompletion stores wrong username field » Password managers are identifying/storing wrong username field when creating a user account

Slightly more accurate issue title, hopefully.

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Dang. It's really too bad that browsers are so stupid. :( (Seriously, on what planet is an input field with an ID of "mail" a username field?!)

This is going to be totally disruptive to people switching between Drupal 7 and 8 who've memorized the tab strokes to get to one field versus another, ugh. OTOH I can't really envision a different fix. We certainly don't want to disable password managers altogether, and it sounds like our options for putting additional attributes are limited since this autocomplete stuff isn't a formal W3C specification.

Therefore, committed and pushed to 8.x.

  • Commit 986faa1 on 8.x by webchick:
    Issue #2191785 by sun: Password managers are identifying/storing wrong...
sun’s picture

Hm. To clarify:

Seriously, on what planet is an input field with an ID of "mail" a username field?!

That is actually the case on probably 98% of all web sites. More or less just the 2% powered by Drupal have a separate notion of username vs. email.

For that reason, there are a range of contributed modules that are removing/replacing the username concept with just the email address. (Which, FWIW, simplifies things a lot and improves the first-time/sign-up user experience; just one form field less means 33% less input.)

I'd totally +1,000 an effort to remove the (enforced) username concept from core and make it optional instead. Everyone expects real names to begin with; a separate "login" name is pointless to have. Wherever we're currently showing this name, we could as well chop-off the alias/mailbox name from the email; i.e., sun@drupal.org turns into "sun", done.

Lastly, to clarify further:

Those modules are not negatively affected by this change. They are removing either the username or the email form input field anyway, so the net result for them is the same: Password managers will identify the input field above the password field as the login username to be stored.

Status: Fixed » Needs work

The last submitted patch, 39: user.form_.39.patch, failed testing.

sun’s picture

Status: Needs work » Fixed

Belated auto-re-test result.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.