Problem/Motivation

Part of a series of reforms for the login system, this patch would ideally allow users to log in using either their username OR their e-mail address, a feature that has previously been provided by the LoginToboggan module.

Steps to reproduce

Proposed resolution

  • Update validation to allow login with email address and not require a username.
  • Change wording of login form to reflect new requirements.

Remaining tasks

User interface changes

  • Fields and wording of login form changed to reflect new requirements.
  • Current Drupal 8 Login

    Proposed Login with Username or Email Address

    Proposed Login with Email Address Only

  • Configuration options added to admin/config/people/accounts
  • Current Drupal 8 admin/config/people/accounts

    Proposed addition to admin/config/people/accounts

Introduced terminology

API changes

Data model changes

Release notes snippet

Problem/Motivation

Proposed resolution

Remaining tasks

User interface changes

API changes

None

CommentFileSizeAuthor
#113 #108_patch_applied_sucessfully.png6.54 KBdbjpanda
#108 111317-name-or-mail-108.patch11.87 KBaaronbauman
#99 interdiff-111317-99.txt533 bytesundertext
#99 111317-name-or-mail-99.patch13.98 KBundertext
#96 111317-name-or-mail-96.patch13.46 KBundertext
#90 NewPeopleAdmin.png146.04 KBchrisla
#90 CurrentDrupalPeopleAdmin.jpg32.69 KBchrisla
#90 NewLogin-EmailOnly.png17.63 KBchrisla
#90 NewLogin-UserOrEmail.png15.79 KBchrisla
#90 CurrentDrupal8Login.jpg17.54 KBchrisla
#79 111317-name-or-mail-79.patch12.9 KBNiklas Fiekas
#75 radios.png146.04 KByesct
#75 drupal-allow_email-111317-75.patch12.86 KByesct
#75 interdiff-73-75.txt552 bytesyesct
#74 select_to_checkbox_beginning-do-not-test.patch1.4 KByesct
#73 drupal-allow_email-111317-72.patch12.86 KByesct
#73 interdiff-70-72.txt759 bytesyesct
#71 interdiff-60-70.txt1.97 KByesct
#70 drupal-allow_email-111317-70.patch12.85 KByesct
#70 interdiff-60-70.txt1.55 KByesct
#60 drupal-allow_users_to_login_using_either_their_username_OR_their_e-111317-60.patch11.88 KByesct
#60 interdiff-49-60.txt4.96 KByesct
#49 111317-49.patch11.5 KBswentel
#49 interdiff.txt6.66 KBswentel
#49 Screen Shot 2013-02-17 at 16.48.23.png16.61 KBswentel
#49 Screen Shot 2013-02-17 at 16.49.01.png17.63 KBswentel
#49 Screen Shot 2013-02-17 at 16.49.40.png15.79 KBswentel
#45 drupal_user_login_email-111317-45.patch11.56 KBhefox
#39 Screen Shot 2012-03-23 at 11.20.41 AM.png49.69 KBaloyr
#39 Screen Shot 2012-03-23 at 11.19.59 AM.png44.65 KBaloyr
#33 111317-user_login_email-33.patch9.99 KBEverett Zufelt
#24 111317-user_login_email-24.patch9.89 KBEverett Zufelt
#8 user.module.patch2.52 KBwmbetts
#6 user.module.patch1.45 KBwmbetts

Issue fork drupal-111317

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

jjeff’s picture

+1 on concept.

hickory’s picture

I would definitely find this useful - even an option that allowed users to *only* login with their email address.

xweb’s picture

+1 / bump
Also for email only registration.

catch’s picture

Version: 6.x-dev » 7.x-dev
Priority: Minor » Normal

bumping to Drupal 7, and a +1 - this is increasingly standard behaviour on lots of different sites, and it would take little effort to implement.

Shai’s picture

+1 on this idea.

I agree with hickory that we should go further than login toboggan. We should remove $user->name from the authentication process using $user->mail alone.

A side benefit to this is that it might make life less complicated for folks who are working very hard on an idea to bring screen name functionality into Drupal: http://drupal.org/node/102679.

Shai
content2zero

wmbetts’s picture

Assigned: Unassigned » wmbetts
Status: Active » Needs review
StatusFileSize
new1.45 KB

The attached patch allows users to login with either their email address or username. It seems to work fine for me, but I'd like other people to review it and report anything they see wrong with it. It's possible I missed something or didn't test a feature that other people use.

It should be noted I saved the patch in notepad before uploading it.
I also wrote this with 7.x-dev in mind.

catch’s picture

Status: Needs review » Needs work

Haven't tested the patch, but it doesn't change any strings - the 'username' field would at a minimum have to be renamed to 'username or e-mail address'.

Additionally, why allow either value in the same field rather than making an extra 'e-mail' field and requiring either? I'm not sure which way is more common on the web and I think I've seen both.

wmbetts’s picture

StatusFileSize
new2.52 KB

You're absolutely correct. I should have changed the field to say "Username or email address". I should have also changed the error message when someone supplies an invalid email, user name, or password.

Attached is a new patch. The patch does the following: validates users on either user name or email address, changes the login for to say "Username / Email Address", changes the invalid login error message to "Sorry, unrecognized username, email address , or password", and it changes the field max size from 60 to 64 reflecting the max sized allowed for the mail field in the database.

I'm not 100% sure if I should change the form field name from name or not.

I save the patch in notepad2 in UNIX format at the recommendation of more experienced developers.

wmbetts’s picture

Status: Needs work » Needs review

I forgot to change the status.

moshe weitzman’s picture

@catch - one textfield is less clutterring than two. so i like the approach proposed here.

but it is disruptive for modules that run validators and such to not know if they have been supplied an email or a password. i recommend that we add a #process or #element_validate to the name textfield and do the query if needed to populate name with a real username if needed. that way, #element_validate and #process run before validors and submit functions so those will be unaffected. hope this makes sense.

catch’s picture

One other thing is we'd probably need some kind of check and/or upgrade path for username@example.com logins provided by drupal/site_network module. The chances of a conflict are pretty slim, but not impossible.

Thinking about 1 vs. 2 fields, where I've used sites that use two, I often find myself squinting to check if there's little red stars next to either, so I'd be pretty happy with a single field overall.

hickory’s picture

Single field is good: if there's an @, assume it's an email address, otherwise assume it's a username. That's what I've been doing with a separate module - it should work as @ isn't allowed in usernames.

catch’s picture

hickory, @ is allowed in usernames. Try registering on groups.drupal.org with hickory@drupal.org

R.Muilwijk’s picture

Status: Needs review » Needs work

For some clients of us we had to implement this. Wouldn't it be better to provide a login method setting so people can choose how the users have to login:

Username,
Email Address,
Both

Let me know your thoughts about this.

philbar’s picture

+1

Subscribe

lastcowboy’s picture

+1

Subscribe

philbar’s picture

Is this going to make it into d7 core?

philbar’s picture

webchick’s picture

Version: 7.x-dev » 8.x-dev

Nope; unfortunately it's a new feature and we closed Drupal 7 for features back in September.

hunmonk’s picture

to anyone trying to code this feature:

it's already fully working in the contrib module LoginToboggan. i encourage you to pull the code from there as a starting point, as it's worked perfectly for a long while, and it handles stuff that the earlier patches haven't thought yet to address -- like making sure one user can't change their username to another user's email address.

hefox’s picture

See issue #1359718: Allow password reset on account with the username matching another email; prevent registrations that match another account about the potential conflict between username and email -- it's already an issue as user/pass assumes they are distinct.

I agree that it'd be most useful if there was a setting for how a user can login. The reason for this is that email is becoming the preferred method, and I believe the more secure option (though I guess that's debatable -- reasoning is that usernames are displayed on the site so got one part of the login, whereas emails are not).

However, should core be supporting that option?

I throw up a sandbox moving the separating the functionality out of of logintoboggan (for various reasons), http://drupal.org/sandbox/hefox/1359748, where I did add that option via a required checkboxes with options username and email, that way can choice both or just one; does that make a sense, UI wise?

Could even add a variable_set in an update so that upgraded sites are set up for username only login.

Everett Zufelt’s picture

Assigned: wmbetts » Everett Zufelt

I'll take a crack at an 8.x patch for this functionality this week.

Everett Zufelt’s picture

Will work on this over the weekend.

Everett Zufelt’s picture

Component: user system » user.module
Assigned: Everett Zufelt » Unassigned
Status: Needs work » Needs review
StatusFileSize
new9.89 KB

This is a first pass implementation.

- Adds user login option to admin/config/people/accounts (options for username, email, or username or email.
- Depending on option modifyies user_login form and user_login_block form
- modifies validation, validates e-mail with valid_email_address(), uses current validation on username (renamed validation funtion from user_login_name_validate() to user_login_username_validate()
- If UUSER_LOGIN_USERNAME_OR_EMAIL is selected then tests validity of email, if not a valid email assumes input is a username
- Modifies authentication functions to authenticate based on option set by admin

Bojhan’s picture

I wonder if we need an option for this at all? Can't contrib provide a module, for those sites that want to disallow logging in with username and e-mail.

izkreny’s picture

IMHO, this feature is more than welcome for community web site builders where you maybe will not be using username at all - and especially not for logging in. So, if you want to make Drupal more easier to use for building above mentioned sites, this is MUST.

Also it would be great to have (hidden API) option to turn off uniqueness of usernames, but this should be follow up issue..

hefox’s picture

I'm in favour of the option as it allows email login only, which is popular, and allows upgrade from 7 sites that are username login.

I'm curious what the rational behind making the setting an single select instead of required check boxes? It seems to add more complexity (needing defines instead of checking what's in an array of options) and would be unflexible for contrib modules adding options in (for example, there's a login via UID module).

Drupal ui standards: http://drupal.org/ui-standards (didn't see anything that would suggest what the proper answer is, though I really think checkboxes matches better).

hefox’s picture

Status: Needs review » Needs work

Needs work do to minor code style.

+    '#type' => 'select',
+  '#title' => t('What credentials can users use to login?'),
+    '#options' => arra
joachim’s picture

> + '#title' => t('What credentials can users use to login?'),

Also, nothing in UI guidelines, but I think we generally avoid labels being written as questions.

Everett Zufelt’s picture

@hefox

I'm curious what the rational behind making the setting an single select instead of required check boxes? It seems to add more complexity (needing defines instead of checking what's in an array of options) and would be unflexible for contrib modules adding options in (for example, there's a login via UID
module).

My rationale is that it is usually easier to get a change commited that has minimal impact on current UI, and my feeling was that a select was less impactful than several checkboxes. I do like the checkbox approach. [ ] e-mail [ ] username, but at least one would need to be checked. Tagging 'needs usability review'.

I don't really see how either approach is easier for extensibility, static enum equivalents, or an array of options, neither of these are the bottleneck of complexity when extending the log in validation / authentication logic. I do, however, agree that to avoid conflicts between multiple modules that attempt to extend the options (login_by_uid and login_by_foo modules), that it would be easier for the options to be represented in code as strings ('email', 'username', 'uid', 'foo') rather than integers ('1', '2', '3', '3'), where contrib modules could choose conflicting integers more easily than conflicting strings.

@joachim

+ '#title' => t('What credentials can users use to login?'),

Also, nothing in UI guidelines, but I think we generally avoid labels being written as questions.

If anyone has suggestions for changes to the UI strings anywhere in the patch please let me know. I admit that selecting UI strings is not one of my strengths.

Everett Zufelt’s picture

Issue tags: +Needs usability review

Would like usability review on questions in #27 and #29

joachim’s picture

My suggestion is:

'#title' => t('Login credentials'),
'#description' => t('The details a user may use to identify themselves'),

Everett Zufelt’s picture

Status: Needs work » Needs review
StatusFileSize
new9.99 KB

New patch takes into consideration comments in #28, #29, #32. Also takes into consideration part of #27 by making static values strings and not integers to make it less likely that modules will provide options with conflicting values.

Sticking with the select element for now, but we can further discuss changing to checkboxes if there is consensus.

+    '#title' => t('Login credentials'),
+    '#description' => t('The details users may use to identify themselves.'),
joachim’s picture

Status: Needs review » Needs work
+++ b/core/modules/user/user.module
@@ -16,6 +16,21 @@ const USERNAME_MAX_LENGTH = 60;
+const USER_LOGIN_USERNAME_ONLY = 'username_only';

If we're using strings, then do we need constants? The machine strings should be understandable as they are.

0 days to next Drupal core point release.

Everett Zufelt’s picture

Status: Needs work » Needs review

Using constants w/ strings makes things easier, particularly during development, when the string changes. I don't know if we hav a code standard for this, but I always prefer to use constants for the ease of changing values.

mathieuhelie’s picture

I have one usability suggestion to make: make passwords optional as well.

This would involve replacing the "request new password" user tab with "connect through email" tab. Users receive the login token in their email account, and they keep it going as long as the cookie doesn't expire. But we would need to remove all suggestions of updating passwords.

Passwords are dangerous - nobody remembers them or they use repeat passwords that are easy to compromise across sites.

webchick’s picture

That sounds like a totally new feature request. Could you file a separate issue for that?

Bojhan’s picture

Sorry, I want to review this - but it would require a screenshot, can anyone take care of that?

aloyr’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new44.65 KB
new49.69 KB

I applied the patch to a fresh drupal 8 git install and tested. I was able to login with my email address once I enabled the feature on the user settings admin screen.

Please see the attached screenshot for the how the login and settings screen look.

sphism’s picture

Just installed patch on fresh d8 install.

Works really nicely, simple to administrate.

I tested the 'username or email address': i can login with either, if i get either wrong it throws the correct errors

tested just email address: i can login with email address, if i try to log in with name it throws the correct error

all looks great to me.

catch’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: -Needs screenshots +Needs usability review
+++ b/core/modules/user/user.moduleundefined
@@ -1210,12 +1225,32 @@ function user_login_block($form) {
+  switch (variable_get('user_login_name_option', USER_LOGIN_USERNAME_ONLY)) {
+    case USER_LOGIN_USERNAME_ONLY:
+      $form['name'] = array('#type' => 'textfield',
+        '#title' => t('Username'),
+        '#maxlength' => USERNAME_MAX_LENGTH,
+        '#size' => 15,
+        '#required' => TRUE,
+      );
+      break;
+    case USER_LOGIN_EMAIL_ONLY:
+      $form['name'] = array('#type' => 'textfield',
+        '#title' => t('E-mail address'),
+        '#maxlength' => EMAIL_MAX_LENGTH,
+        '#size' => 15,
+        '#required' => TRUE,
+      );
+      break;
+    case USER_LOGIN_USERNAME_OR_EMAIL:
+      $form['name'] = array('#type' => 'textfield',
+        '#title' => t('Username or e-mail address'),
+        '#maxlength' => EMAIL_MAX_LENGTH,
+        '#size' => 15,
+        '#required' => TRUE,
+      );
+      break;

Several of these are the same - could we set some defaults then just change the relevant pieces in the switch?

Also it'd be good to clean up the '#type' being on the same line as the array declaration, I'm sure that's user module violating coding standards.

+++ b/core/modules/user/user.moduleundefined
@@ -2070,9 +2126,35 @@ function user_login_default_validators() {
+ * A FAPI validate handler. Depending on user_login_name_option, delegates
+ *   validation to user_login_username_validate() and valid_email_address().
  */
 function user_login_name_validate($form, &$form_state) {
+  if (isset($form_state['values']['name'])) {
+    switch (variable_get('user_login_name_option', USER_LOGIN_USERNAME_ONLY)) {

This should probably be renamed? Not sure what to though...

+++ b/core/modules/user/user.moduleundefined
@@ -2096,7 +2178,23 @@ function user_login_authenticate_validate($form, &$form_state) {
-    $account = db_query("SELECT * FROM {users} WHERE name = :name AND status = 1", array(':name' => $form_state['values']['name']))->fetchObject();
+    $account = FALSE;
+    switch (variable_get('user_login_name_option', USER_LOGIN_USERNAME_ONLY)) {
+      case USER_LOGIN_USERNAME_ONLY:
+        $account = db_query("SELECT * FROM {users} WHERE name = :name AND status = 1", array(':name' => $form_state['values']['name']))->fetchObject();
+        break;
+      case USER_LOGIN_EMAIL_ONLY:
+        $account = db_query("SELECT * FROM {users} WHERE mail = :mail AND status = 1", array(':mail' => $form_state['values']['name']))->fetchObject();
+        break;
+      case USER_LOGIN_USERNAME_OR_EMAIL:
+      if (valid_email_address($form_state['values']['name'])) {
+        $account = db_query("SELECT * FROM {users} WHERE name = :name AND status = 1", array(':name' => $form_state['values']['name']))->fetchObject();
+        }
+        if (!$account) {
+        $account = db_query("SELECT * FROM {users} WHERE name = :name AND status = 1", array(':name' => $form_state['values']['name']))->fetchObject();
+        }
+        break;

This doesn't look right. the USER_LOGIN_USERNAME_OR_EMAIL hunk is running the same query twice against name, shouldn't it be checking the e-mail address the first time? If that's the case, we should also add test coverage for this.

Also resetting tags now there's a screenshot.

kscheirer’s picture

I think we should look at shamelessly stealing code from LoginToboggan, which already has this feature, and has had a lot more eyeballs on it over the years.

xlyz’s picture

@ kscheirer:
email registration seems a more relevant solution.

Bojhan’s picture

Issue tags: -Needs usability review

Looks like we are applying the standard here, so good from my point of view

hefox’s picture

Status: Needs work » Needs review
StatusFileSize
new11.56 KB

Updated patch for config changes, combined some stuff to cut down on the duplicate/similar logic, and added some tests.

scor’s picture

+++ b/core/modules/user/config/user.settings.yml
@@ -1,5 +1,6 @@
+user_login_name_option: username_only

If you're talking about an option like the variable name says, I would expect its value to be ON/OFF or TRUE/FALSE. Given that the values are explicit, why not call that variable a method? something like user_login_method or user_login_name_method.

+++ b/core/modules/user/lib/Drupal/user/Tests/UserLoginTest.php
@@ -21,6 +21,33 @@ public static function getInfo() {
+   * Test that login credientials work. ¶

typo and ending white space

yesct’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update

updating issue summary and adding tags.

updated screenshots would be helpful to make sure things have not changed.

interdiff and tests only patch would help

marking it needs work to get this ready for a committer to look at (like updated screenshot and tests only patch for the testbot).

I think at least the white space #46 should be addressed.

yesct’s picture

Issue tags: +Novice

some of these tasks are Novice

swentel’s picture

Status: Needs work » Needs review
Issue tags: -Novice
StatusFileSize
new15.79 KB
new17.63 KB
new16.61 KB
new6.66 KB
new11.5 KB

Here's screens, interdiff and updated patch. This is ready to fly imo.

Screen Shot 2013-02-17 at 16.48.23.png

Screen Shot 2013-02-17 at 16.49.01.png

Screen Shot 2013-02-17 at 16.49.40.png

Status: Needs review » Needs work
Issue tags: -Usability, -Needs issue summary update

The last submitted patch, 111317-49.patch, failed testing.

swentel’s picture

Status: Needs work » Needs review

#49: 111317-49.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +Usability, +Needs issue summary update

The last submitted patch, 111317-49.patch, failed testing.

joachim’s picture

The use of a SELECT seems a bit weird UI.

Why not checkboxes, and tick both to mean 'Username or e-mail address'?

swentel’s picture

checkboxes would make the submission and form logic a bit more convoluted. Maybe radio buttons might be better ?

joachim’s picture

But then how would you pick both email and username?

It will indeed make code more complicated, but that's because the way the user will think about this and the way the system thinks about this are completely different unfortunately.

Take a step back and consider that this is kinda wacky UI:

() A
() B
() A or B
yesct’s picture

checkboxes... we would not want someone to uncheck both.

what are the admin choices:
() username
() email or username

are we adding also to allow
() email
where username is not used for logging in, and force using email address? (answering my own question:) I looked at the patch and yes.

I suggest next steps,

  • lets use radio buttons
  • get a screenshot of that, even though it is strange.
  • file a small follow-up issue to refactor the code to allow using checkboxes.

@swentel http://drupal.org/node/1859584 has some hints for how to get a screenshot with a select dropped down so we can see all the choices in it.

joachim’s picture

> checkboxes... we would not want someone to uncheck both.

Make them required :)

yesct’s picture

+++ b/core/modules/user/lib/Drupal/user/Tests/UserLoginTest.phpundefined
@@ -22,6 +22,33 @@ public static function getInfo() {
+  /**
+   * Test that login credentials work.
+   */
+  function testLoginByEmail() {
+    $account = $this->drupalCreateUser(array());
+
+    // Login via name.
+    $this->drupalLogin($account);
+    $this->assertFailedLogin($account, NULL, TRUE);
+
+    // Login via email only.
+    config('user.settings')
+      ->set('user_login_method', USER_LOGIN_EMAIL_ONLY)
+      ->save();
+    $this->drupalLogin($account, TRUE);
+    $this->assertFailedLogin($account);
+
+    // Login via name or email.
+    config('user.settings')
+      ->set('user_login_method', USER_LOGIN_USERNAME_OR_EMAIL)
+      ->save();;
+    $this->drupalLogin($account, TRUE);
+    $this->drupalLogin($account);

a comment at the beginning with what the default user login method is might help clarify.

I need to look more closely at this to understand it.

I think the last case here, with the OR method should test both logging in with username and email. Maybe that is what the TRUE option to drupalLogin is doing.

We dont need an assert it was successful?

Hm. actually, I think I get it. I might have a patch for improving the comments here later. (not blocking this)

I'll update the issue summary remaining tests to remove the task to add tests since they are there. :)

yesct’s picture

Issue summary: View changes

Updated issue summary to add remaining tasks to make it easier for new people

yesct’s picture

I'm thinking something like:

    // Login via name, the default method.
    // Using email should fail.
    $this->assertFailedLogin($account, NULL, TRUE);
    // Using username should pass.
    $this->drupalLogin($account);

    // Login test with email only method.
    config('user.settings')
      ->set('user_login_method', USER_LOGIN_EMAIL_ONLY)
      ->save();
    // Using email should pass.
    $this->drupalLogin($account, TRUE);
    // Using username should fail.
    $this->assertFailedLogin($account);

    // Login via name or email method.
    config('user.settings')
      ->set('user_login_method', USER_LOGIN_USERNAME_OR_EMAIL)
      ->save();;
    // Using email should pass.
    $this->drupalLogin($account, TRUE);
    // Using username should pass.
    $this->drupalLogin($account);

added comments (need to check the api for drupalLogin and assertFailedLogin)
and switched the order of the tests in the first group so each group is: 1) email 2) username.

I can do the patch for this later, recording notes because I'm interrupted for now. It's ok if someone wants to do it before I get back to it.

[edit: need better worded comments. Like using username consistantly (not name) and e-mail instead of email I think...]

yesct’s picture

Status: Needs work » Needs review
StatusFileSize
new4.96 KB
new11.88 KB

I'm confused. Looking at the code, I expected a second parameter to WebTestBase drupalLogin
http://api.drupal.org/api/drupal/core%21modules%21simpletest%21lib%21Dru...

doh! right, this patch changes that. *grin*

similar with assertFailedLogin
http://api.drupal.org/api/drupal/core%21modules%21user%21lib%21Drupal%21...

+++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.phpundefined
@@ -621,16 +621,18 @@ protected function checkPermissions(array $permissions, $reset = FALSE) {
+   * @param $by_email

+++ b/core/modules/user/lib/Drupal/user/Tests/UserLoginTest.phpundefined
@@ -139,10 +166,15 @@ function testPasswordRehashOnLogin() {
+   * @param $by_email

should have type (bool)
http://drupal.org/node/1354#types

+++ b/core/modules/user/lib/Drupal/user/Tests/UserLoginTest.phpundefined
@@ -157,7 +189,22 @@ function assertFailedLogin($account, $flood_trigger = NULL) {
+          break;
+        case USER_LOGIN_EMAIL_ONLY:

case looks like should have blank lines.

+++ b/core/modules/user/user.moduleundefined
@@ -1312,12 +1328,26 @@ function user_login_default_validators() {
- * A FAPI validate handler. Sets an error if supplied username has been blocked.
+ * A FAPI validate handler. Depending on user_login_method, delegates
+ * validation to user_login_username_validate() and valid_email_address().

needs to be one line.

Also, I dont understand this comment and user_login_username_validate() is not a function I could find anywhere.

-------------------

patch attached.

yesct’s picture

Status: Needs review » Needs work

needs work to make required, 2 checkboxes:
E-mail
Username

thanks @joachim

yesct’s picture

Status: Needs review » Needs work
Issue tags: +Usability, +Needs issue summary update
yesct’s picture

yep. enabling testing locally, and then going to the testing list whitescreens.

I checked each of the files effected by this patch for php syntax errors and did not find any, still looking for cause.

kscheirer’s picture

+++ b/core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.phpundefined
@@ -621,16 +621,18 @@ protected function checkPermissions(array $permissions, $reset = FALSE) {
-      'name' => $account->name,
+      'name' => $by_email ? $user->mail : $user->name,

Shouldn't this be $account instead of $user?

yesct’s picture

yeah, that looks like it should be account.

I tried tests locally with that change, and still whitescreen.
Then I started removing the tests...

How do people debug a situation like this?

jaypan’s picture

WSOD can be generally be debugged by looking at your PHP and Server logs.

kscheirer’s picture

It's kind of buried in the testbot report details, but way at the bottom there's:

[00:22:29] Command [/usr/bin/php ./core/scripts/run-tests.sh --concurrency 8 --php /usr/bin/php --url 'http://drupaltestbot659-mysql/checkout' --keep-results --all 2>&1] failed
Duration 1 seconds
Directory [/var/lib/drupaltestbot/sites/default/files/checkout]
Status [255]
Output: [PHP Fatal error: Class 'Insert' not found in /var/lib/drupaltestbot/sites/default/files/checkout/core/modules/rest/lib/Drupal/rest/Tests/RESTTestBase.php on line 215

Fatal error: Class 'Insert' not found in /var/lib/drupaltestbot/sites/default/files/checkout/core/modules/rest/lib/Drupal/rest/Tests/RESTTestBase.php on line 215].

does that help at all?

yesct’s picture

@larowlan helped me during core office hours to figure out that REST in extending drupalLogin!
So we have to add the arg there too.
grep -R "function drupalLogin" *
shows just that one to fix.

patch coming soon.

yesct’s picture

Status: Needs work » Needs review
StatusFileSize
new1.55 KB
new12.85 KB

this fixes #65, removes a newline that was extra, and attempts to fix the whitescreen by adding the 2nd argument to the REST drupalLogin.. (but it still whitescreens).

I followed http://geek.michaelgrace.org/2011/08/xdebug-cachegrind-and-mamp-on-mac-osx/ to set up Xdebug, and while my info.php says it's enabled, I dont get any more information on the whitescreen.

yesct’s picture

StatusFileSize
new1.97 KB

oops. that was an earlier interdiff. here is the correct one (just shows that newline change)

Status: Needs review » Needs work

The last submitted patch, drupal-allow_email-111317-70.patch, failed testing.

yesct’s picture

Status: Needs work » Needs review
StatusFileSize
new759 bytes
new12.86 KB

ah, the function args need to be *identical* (thanks @larowlan)

no whitescreen and the user login test passes locally.

next, to change the radios into required checkboxes

yesct’s picture

here was a start at converting the select to checkboxes (where checking one would be required).

I could not find another example in core of doing that... and I could not figure out if it was possible.

yesct’s picture

StatusFileSize
new552 bytes
new12.86 KB
new146.04 KB

well, here it is as radios.
radios.png

batigol’s picture

Interesting. I must test it !

larowlan’s picture

Status: Needs review » Reviewed & tested by the community

Code looks great.
Tests look great.
Works as advertised when testing manually.
Great feature.
Want to see this in Drupal 8?
Help us get thresholds down....see http://buytaert.net/code-freeze-and-thresholds for more information on why this might still sneak in....

Anonymous’s picture

Patch failed against the latest version of Core.

drupal8 paul$ git apply drupal-allow_email-111317-75.patch
error: patch failed: core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php:621
error: core/modules/simpletest/lib/Drupal/simpletest/WebTestBase.php: patch does not apply

Niklas Fiekas’s picture

Status: Reviewed & tested by the community » Needs review
StatusFileSize
new12.9 KB

Did a quick reroll. Looks like #1757098: Add types to return values of webTestBase methods was modifying code nearby.

yesct’s picture

Status: Needs review » Reviewed & tested by the community

back to rtbc
since that was just a re-roll.

yesct’s picture

#79: 111317-name-or-mail-79.patch queued for re-testing.

xjm’s picture

#79: 111317-name-or-mail-79.patch queued for re-testing.

catch’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Security
+++ b/core/modules/user/user.moduleundefined
@@ -1285,12 +1301,30 @@ function user_login_default_validators() {
+      if ($account = db_query("SELECT * FROM {users} WHERE mail = :mail", array(':mail' => $name))->fetchObject()) {
+        $name = $account->name;

This could just be SELECT name then fetchField().

+++ b/core/modules/user/user.moduleundefined
@@ -1313,7 +1347,15 @@ function user_login_authenticate_validate($form, &$form_state) {
+    $credentials = config('user.settings')->get('user_login_method');
+    if ($credentials != USER_LOGIN_USERNAME_ONLY && valid_email_address($form_state['values']['name'])) {
+      $account = db_query("SELECT * FROM {users} WHERE mail = :mail AND status = 1", array(':mail' => $form_state['values']['name']))->fetchObject();
+    }
+    if (!$account && $credentials != USER_LOGIN_EMAIL_ONLY) {
+      $account = db_query("SELECT * FROM {users} WHERE name = :name AND status = 1", array(':name' => $form_state['values']['name']))->fetchObject();

First time reading this through I was concerned about usernames that look like e-mail addresses but aren't - such as those which the old Drupal module used to create (killes@www.drop.org is one), but since this falls back to name in the case that email fails that seems fine.

However I'm concerned about the following case:

User A has the username foo@example.com

User B has the e-mail address foo@example.com

If User B is blocked, then won't user A be locked out of the site?

This could also happen for very old sites where someone's registered more than once.

Once you've registered an account there's no requirement for e-mail validation, so in the case of killes someone could register with their own e-mail, change it to killes@www.drop.org, post some spam to the core issue queue, and now killes can't log in.

At a minimum, I think we need validation when new users register that their username matches neither an existing username nor an existing e-mail address.

For sites with accounts in this condition there's not a great deal that can be done but maybe a warning in the upgrade process?

Tagging with security.

jaypan’s picture

Nice catch.

star-szr’s picture

#83:

At a minimum, I think we need validation when new users register that their username matches neither an existing username nor an existing e-mail address.

This validation is part of the patch at #1359718: Allow password reset on account with the username matching another email; prevent registrations that match another account.

pancho’s picture

[edit:]
Moved comment to a new issue #2014185: Check usernames that are email addresses more rigidly, only allow if matches email. Would be very grateful for opinions on that!

pancho’s picture

Status: Needs work » Needs review
Issue tags: -Usability, -Needs issue summary update, -Security

#79: 111317-name-or-mail-79.patch queued for re-testing.

Status: Needs review » Needs work
Issue tags: +Usability, +Needs issue summary update, +Security

The last submitted patch, 111317-name-or-mail-79.patch, failed testing.

cristiroma’s picture

The current user.module diverged too much from the original code from March.
Function user_login_name_validate was removed and I think the validation system has changed.
This would need to be rewritten.

cristiroma’s picture

Issue summary: View changes

the missing interdiff was done. updated remaining tasks

chrisla’s picture

Issue summary: View changes
StatusFileSize
new17.54 KB
new15.79 KB
new17.63 KB
new32.69 KB
new146.04 KB
mgifford’s picture

This patch needs to be rewritten now. Most of the hunks no longer apply.

batigol’s picture

Yeap if it's done then I can turn off one more module. Maybe module developers could help here (this one I'm using all the time - https://drupal.org/project/logintoboggan)?

pancho’s picture

Marked #2192125: Allow users to log in with e-mail as username a duplicate of this one here.

jibran’s picture

Issue tags: +Needs reroll

Can we please move forward here? It's 2014 and I don't want to remember my username for every site.

undertext’s picture

Assigned: Unassigned » undertext
undertext’s picture

Status: Needs work » Needs review
StatusFileSize
new13.46 KB

Rewrote the patch. Just applying the same logic to the new codebase API.

Status: Needs review » Needs work

The last submitted patch, 96: 111317-name-or-mail-96.patch, failed testing.

jibran’s picture

+++ b/core/modules/user/config/install/user.settings.yml
@@ -1,5 +1,6 @@
+user_login_method: username_only

I think we have to update user.schema.yml as well.

undertext’s picture

Status: Needs work » Needs review
StatusFileSize
new13.98 KB
new533 bytes
jibran’s picture

Status: Needs review » Needs work

the only pending thing

At a minimum, I think we need validation when new users register that their username matches neither an existing username nor an existing e-mail address.

jibran’s picture

Status: Needs work » Postponed
Issue tags: -Needs issue summary update, -Needs reroll
m1r1k’s picture

Issue tags: +#ams2014contest
Anonymous’s picture

Issue tags: -

Is this 8 year old unsolved issue a record holder or what? :D

Leeteq’s picture

@ivanjaros; nope, not even close to that record.

alimac’s picture

Issue tags: +Needs reroll
alimac’s picture

Issue summary: View changes
Anonymous’s picture

aaronbauman’s picture

StatusFileSize
new11.87 KB

rerolled #99 on latest dev

MakeOnlineShop’s picture

Hello, login toboggan for Drupal 8 isn't working and I think that email and facebook login are essential in 2016, so is it going to be in core ?

Thanks.

jaypan’s picture

Anything not in core will not be added later. So no, those won't be in core.

Also, as this question has nothing to do with the issue queue you've posted in, you should open a new thread in the forums, or in the issue queue(s) for the module(s) in question rather than posting in an unrelated issue.

learnbydrop’s picture

#99 and #108 patches are not working.

Error messages are showing with the patches.

dbjpanda’s picture

Issue summary: View changes
Issue tags: -Needs reroll
StatusFileSize
new6.54 KB

soorepalli : i am able to apply the patch in #108 without getting any error.https://www.drupal.org/files/issues/%23108_patch_applied_sucessfully.png

jhedstrom’s picture

Version: 8.0.x-dev » 8.2.x-dev

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

anybody’s picture

16 years later, I think this should be discussed again. There are surely usecases where a "Username" is very untypical and the requirement for a username shouldn't be enforced by a CMS & Framework like Drupal.

One typical example is eCommerce. I know no relevant Shop system that requires a users to enter a username. Same for many many SaaS projects, where the eMail Address is the login.

So while there are workarounds in contrib, I think we should really have a discussion, if the enforcement of a username is still the right way to go for the many use-cases of Drupal?

anybody’s picture

catch’s picture

This is still probably blocked on #1359718: Allow password reset on account with the username matching another email; prevent registrations that match another account and #2014185: Check usernames that are email addresses more rigidly, only allow if matches email - i.e. what happens if one user's email address is user@example.com and another user's username is user@example.com?

I do think we should consider at least a configuration option to allow logging in with e-mail or username in core, it's an extremely common pattern.

That's different from allowing e-mail-only registration though which would be https://www.drupal.org/project/email_registration in core. That gets a lot trickier because we need something to put as display name (content and comment authors), and that defaults to username.

anybody’s picture

Thanks @catch totally agree - perhaps this topic would be worth a fresh issue too?

One thing regarding your last sentence: I think also that discussion would make a lot of sense for Drupal Core as modern Framework (not specifically as CMS, but as general purpose, Commerce Platform, SaaS foundation etc.): Using no "Username" at all, which means at least hiding the fields entirely for users and site-admins should really be considered not to be a contrib thing.
10Y ago we were in a world, where usernames were common for many things like Forums, Communities etc., but today I think at least 50% of web projects / SaaS with user registrations (excluding things like Communities, where the email address needs to be hidden and an alias used of course), do not use usernames and don't confront users (and developers / site builders!) with it. And I really think Drupal *should* have Username optional in Core long-term.

Or in other words: Think of modern SaaS or Headless frameworks like https://appwrite.io/ or https://directus.io/ I don't think one would hard-code the requirement for a username anymore for user accounts. But Drupal has a different history, where username was best-practice. But I don't think we should stick to that.

One typical example is Drupal Commerce: To register a customer account you have to enter a username (of not using contrib). Which other Commerce system does that? (Hopefully none, for good reasons - it doesn't fit this use-case)

Of course, I know this won't be an easy job, so what I'm talking about here is the strategic perspective.

So should we proceed here or in (separate) issue(s)?

catch’s picture

@AnyBody I think it's worth splitting out yeah. There are at least two tracks:

1. Allow user to log in with their e-mail address OR username on the login form - PP on the two issues about e-mail-like usernames. This is not necessarily going to be easy to get done but the scope is quite small and it makes sense in its own right, and for me it would be a normal core feature request.

2. Provide an option to make usernames optional. This has considerably larger scope and it might need to go in the ideas queue of product manager sign-off. While it's a common use-case, projects that don't require usernames will invariably customize the display name, to use first and last names, and core doesn't have anything like that. So we need to ask and answer questions like: - what can be used for display name if username is empty? What happens to the unique, required database column? etc. This would then need its own meta implementation issue for the various bits.

pameeela’s picture

+1 for fresh issues, let's do that! Had the same thought while scrolling through and seems there is consensus :) We can transfer credit to the initial issue for point 1. Don't have time to do this now but I will if no one beats me to it.

bhanu951’s picture

Assigned: undertext » Unassigned

bhanu951’s picture

Re-rolled patch from #108 to 11.x branch.

It still needs update hook to update new config.

bhanu951’s picture

Status: Active » Needs work
quietone’s picture

Issue summary: View changes
Status: Needs work » Postponed
Issue tags: +Needs screenshots

If I read the last few comments correctly this should be postponed on #1359718: Allow password reset on account with the username matching another email; prevent registrations that match another account and #2014185: Check usernames that are email addresses more rigidly, only allow if matches email. And a new issue made for #134 point #2. I updated the issue summary accordingly. Also, hide all the files.

This will also need up to date screenshots, so I tagged for that.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.