Problem/Motivation

If the 'Name' provided for a comment matches a registered user account, the comment can't be saved. This applies to posting new comments or admins editing existing comments.

Steps to reproduce

  1. Install Drupal
  2. Create an article with comments open
  3. As an anonymous user, post a comment with an empty value for 'Name'
  4. As admin, create a user account with username 'Anonymous'
  5. As admin, edit the previous comment posted by anonymous user and see you get a validation error
  6. As anonymous user, confirm you can still post comments with empty value for 'Name' and they are created as 'Anonymous'
  7. As anonymous user, try to post a comment with 'Anonymous' as 'Name' and see you get a validation error

(Note the same occurs with any Name/username, not just Anonymous)

Proposed resolution

Perhaps do this validation for anonymous comments, since 'Name' is just a plain text field? It shows (not verified) for anon users next to the name provided. And comments by the registered user link to the user profile by default. So there is a way to distinguish them:

Remaining tasks

  1. Agree on a resolution
  2. Write a patch with tests
  3. Review

User interface changes

API changes

Data model changes

Release notes snippet

Original issue summary

Hi,
I am trying to get 2.3 to work, but I am stuck on "The name belongs to a registered user.".
I set "access secured pages" permission for securesite also to anonymous users.
How to get this message away and securesite working?
I got a blank field for guest user, and am not able to type something in it, but it has a red border around it.

Thanks for going into this.
Greetings, Martijn

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Darren Oh’s picture

Status: Active » Closed (fixed)

This means that one of your users has created an account with the same name you are using for the guest user. You must change either the user name or the guest name.

Summit’s picture

Hi,
You where right! Somehow I got a user with Anonymous user as name in my useradmin. I deleted this user, and now it works.
Thanks for your quick reply!

greetings,
Martijn

podarok’s picture

Project: Drupal core » Secure Site
Version: 6.x-dev » 6.x-2.3
Component: comment.module » Code

this is real trouble on large loaded sites

cause

if Your site was for anonymous users but during its growing process Your users became registered with the same names - trouble is global
F.E. content manager wants to edit old message - but always got this error. Changing names - is not good - sometimes it can be non-legal (copyright)

If this bug (Yes, this is bug! cause superadmin may edit everything!) woudn`t be fixed try this small fix in comment.module

        $taken = db_result(db_query("SELECT COUNT(uid) FROM {users} WHERE LOWER(name) = '%s'", $edit['name']));

/*
	   if ($taken != 0) {
          form_set_error('name', t('The name you used belongs to a registered user.'));
        }
*/
      }

But remember!!!! - with commenting this code users can change their usernames in comments into Registered usernames (possible)

ps. sorry for my english

podarok’s picture

Project: Secure Site » Drupal core
Version: 6.x-2.3 » 6.x-dev
Component: Code » comment.module
Priority: Normal » Critical
Status: Closed (fixed) » Needs work

moving this to core comment.module queue

we need to handle such situation in right way

podarok’s picture

Project: Secure Site » Drupal core
Version: 6.x-2.3 » 7.x-dev
Component: Code » comment.module
Priority: Critical » Normal

just checked this in 7.x-dev - all the same

gpk’s picture

Title: Message: "The name belongs to a registered user" and securesite not working » Message: "The name belongs to a registered user" - can't edit old comments and usability problem for registered users
Status: Needs work » Active
Issue tags: +Usability

#3 describes a situation where a comment administrator can end up not being able to edit an existing comment.

Also for people who have registered and try to post a comment when they are not logged in - they may get this message, but it's really no help to them so they give up. I've worked round this using string overrides so that they also get a link to the login page, but a better answer would be for them to be shown a password box on the error screen so that they can log in and post the comment all at once. Otherwise they have to type their comment in again once they've logged in, which is pretty cruel!

Also updating title to be more meaningful.

a6hiji7’s picture

This is really a bug. It's a real pain with common names like "Michael" and "George". Will love to see this check removed from the comment module. I think the "name" field in "comments" table should not have anything to do with the user as the "uid" field is already there to track the user.

roedelius’s picture

Title: can't edit anonymous comments if the given name has been taken by a newer user account » Message: "The name belongs to a registered user" - can't edit old comments and usability problem for registered users

Echoing #7. This is definitely a bug and bad UX. Let's say there's a "steve" username (or "Steve", or "STEVE" - case doesn't matter). If Steve isn't logged in, or another Steve in the world wanted to comment, they're presented with "The name you used belongs to a registered user". Steve's choices are to either type in his full name, intentionally misspell his name, or leave a fake/random name.

As far as I can tell, uid can remain 0 and name can be anything, so what's the point of this validation? And should this be a new ticket?

joachim’s picture

Title: Message: "The name belongs to a registered user" - can't edit old comments and usability problem for registered users » can't edit anonymous comments if the given name has been taken by a newer user account

So here's the quick steps on how to reproduce this:

1. while logged out, add a comment to a node, giving your name as, say, 'Bob'.
2. as uid 1, create a user called 'Bob'
3. as uid 1, try to edit the comment and save it.

> Also for people who have registered and try to post a comment when they are not logged in

I think this is a separate matter -- feature request to have login fields within the comment form perhaps? Though I bet there's a contrib module for that already ;)

So sticking to the main issue, the problem is not what code to write, but how to handle this situation. There's a principle of Drupal of protecting people's identities -- that is why we don't allow duplicate usernames.

Some ideas:

a) When an account is created, check ALL comment names and reject the new account name if an anonymous comment already bears that name. -- this is patently absurb, so let's move on ;)
b) When editing the anonymous comment, run a check on the name field, and warn the admin of the situation. This allows the admin to do something about it before getting the submit warning -- like changing the name field. For bonus points, the form could show the warning AND change the name field to 'Bob (visitor)', or 'Bob (Anonymous)'.

Other than that, I'm not sure... any more ideas?

yngens’s picture

Title: Message: "The name belongs to a registered user" - can't edit old comments and usability problem for registered users » can't edit anonymous comments if the given name has been taken by a newer user account

subscribe

mingos’s picture

I modified the code like this:

$taken = db_result(db_query("SELECT COUNT(uid) FROM {users} WHERE LOWER(name) = '%s'", $edit['name']));
if ($taken != 0) {
    $email = db_result(db_query("SELECT mail FROM {users} WHERE LOWER(name) = '%s'", $edit['name']));
    if ($email != $edit['mail']) form_set_error('name', t('The name you used belongs to a registered user.'));
}

So, if the username is already taken, it also considers the email. If the username/email pair exists in the database, the comment is allowed, otherwise the standard "name taken" error is displayed.

ivrh’s picture

The issue exists in Drupal's comment core module for websites where only anonymous users post comments.
This should definitely be changed to check email instead, as email is site-wide unique identifier of site visitor, not name. Anonymous users don't need site account just to post a comment or reply and this is totally confusing the way it works at the moment.

ivrh’s picture

Version: 7.x-dev » 6.20
Status: Active » Needs review

Here's the patch with proposed change (against version 6.x). This patch will work the old way but will skip username check if Anonymous users may post comments.
Let me know if this is good enough and I will post the patch file.

--- Base (BASE)
+++ Locally Modified (Based On LOCAL)
@@ -1201,7 +1201,7 @@
if (!$user->uid || isset($edit['is_anonymous'])) {
$node = node_load($edit['nid']);
if (variable_get('comment_anonymous_'. $node->type, COMMENT_ANONYMOUS_MAYNOT_CONTACT) > COMMENT_ANONYMOUS_MAYNOT_CONTACT) {
- if ($edit['name']) {
+ if ($edit['name'] && !user_access('access comments')) {
$taken = db_result(db_query("SELECT COUNT(uid) FROM {users} WHERE name = '%s'", $edit['name']));

if ($taken != 0) {

joachim’s picture

Version: 6.20 » 7.x-dev

Please don't change the version number -- this needs to be fixed on 7 first.

Also, can you upload rather than paste your patch please?

sun’s picture

Version: 7.x-dev » 8.x-dev
Status: Needs review » Active
Issue tags: -Usability +Needs tests

A patch for this issue needs to contain a test to reproduce the bug, following the steps in #9. This patch should not contain a fix, just the test to prove that this bug still exists and can be cleanly reproduced.

pillarsdotnet’s picture

andypost’s picture

andypost’s picture

Anonymous author still pita

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

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.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.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should 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.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should 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.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should 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.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should 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.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should 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.

Darren Oh’s picture

Issue tags: +fldc19
volkswagenchick’s picture

Issue tags: +midcamp2019
pbirk’s picture

I think this patch addresses the test request in #15. On my development machine, the test fails where I'd expect:

Testing Drupal\Tests\comment\Functional\CommentInterfaceTest
F...                                                                4 / 4 (100%)

Time: 5.27 minutes, Memory: 6.00MB

There was 1 failure:

1) Drupal\Tests\comment\Functional\CommentInterfaceTest::testCommentInterface
"vWMdUNQz" found
Failed asserting that false is true.

/var/www/drupal-dev-8/core/tests/Drupal/KernelTests/AssertLegacyTrait.php:35
/var/www/drupal-dev-8/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php:145
/var/www/drupal-dev-8/core/tests/Drupal/FunctionalTests/AssertLegacyTrait.php:84
/var/www/drupal-dev-8/core/modules/comment/tests/src/Functional/CommentTestBase.php:166
/var/www/drupal-dev-8/core/modules/comment/tests/src/Functional/CommentInterfaceTest.php:124

I assume the next step is to create a patch that fixes the behavior. I should be able to look into that either this week or next.

pbirk’s picture

Version: 8.6.x-dev » 8.8.x-dev
DamienMcKenna’s picture

Status: Active » Needs review

Let's run the tests to confirm that the bug exists and the tests can trigger it.

Status: Needs review » Needs work

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.

pameeela’s picture

Title: can't edit anonymous comments if the given name has been taken by a newer user account » 'Name' value for anonymous comments can conflict with registered usernames
Issue summary: View changes
Issue tags: +Bug Smash Initiative
FileSize
55.6 KB
46.69 KB
27.53 KB

Updated IS to clarify the issue, but I don't know what the right solution is. I think it's not really necessary to validate the 'Name' provided by anonymous users, and it doesn't make sense to reserve these values as usernames. But I don't deal with sites that use commenting so this definitely needs input from folks who do.

pameeela credited alexpott.

pameeela credited bleen.

pameeela’s picture

joachim’s picture

The two issues seem unrelated to me -- this one should be fixed in comment module, and the other one in user module.

pameeela’s picture

Somewhat puzzled as to how they seem unrelated, since the steps to reproduce here describe the other issue exactly.

I think the only difference is the proposed solution. But I don't think there is a need to disallow users from registering with the anon username, as long as it doesn't interfere with commenting, as this issue proposes.

If you think there is a separate fix needed to the user module please do re-open the other issue, I think it just needs an issue summary update to make it clear.

joachim’s picture

The other issue, #903606: Don't allow users to register with name the same as the Anonymous name is this:

1. The site is set up to show the label 'Anonymous user' for anonymous users, anywhere where the anonymous user might be involved -- comment author, but also node author, etc etc.
2. Someone create sa user account and enters the username 'Anonymous user' for that account.
3. This is confusing, because things created by a registered user now say 'Anonymous user'.

This issue is this:

1. An anonymous user posts a comment. In the comment form, they can write their name. This is a simple text field. They put 'Kermit the frog'.
2. Someone else later creates a user account, and enters the username 'Kermit the frog'.
3. It not looks like the comments created by the anonymous user were created by the authenticated user 'Kermit the frog', but they are not.

The other issue is fixed with validation in the user module to prevent a username being registered which matches the site config for the anonymous user label.

This issue is fixed with validation in the comment module to prevent a username being registered which matches the name field on any existing comment.

pameeela’s picture

I guess the other issue is described badly then because it only mentions comments as a problem and specifies that the issue is that anonymous users are blocked from submitting the form if someone has the username that is allocated to anonymous users.

Perhaps the best way forward is a new issue for 'Prevent a username being registered which matches the site config for the anonymous user label'?

Edit: I realised that the other issue title was effectively this, but the issue summary wasn't and it only referred to comments. So maybe the other issue just needs to be reopened with a better summary.

pameeela’s picture

Tested on the node form and it works fine, posted more info at #903606-41: Don't allow users to register with name the same as the Anonymous name.

catch’s picture

3. It not looks like the comments created by the anonymous user were created by the authenticated user 'Kermit the frog', but they are not.

The other issue is fixed with validation in the user module to prevent a username being registered which matches the site config for the anonymous user label.

This issue is fixed with validation in the comment module to prevent a username being registered which matches the name field on any existing comment.

I'm not sure this is a problem, or at if it is that preventing registration with those names is desirable:

- we add (not verified) after anonymous comment usernames, so there's a clear indication that no-one was logged in.

- there's validation to prevent the opposite case, of anonymous comments being posted with a registered username, so you won't get into the situation where the anonymous and logged-in usernames are both on the same active comment threads at the same time.

- What is the message from the comment validation? Would it say someone else has already registered the username? They haven't really, but saying someone left a comment with that anonymous display name seems like a strange validation message to get when registering an account.

- What if I've been posting anonymously as 'catch', then I want to register an account as 'catch' - now I can't do that.

One option would be some kind of advisory message instead of a hard validation error, but we don't really have a great place to do that.

joachim’s picture

> - there's validation to prevent the opposite case, of anonymous comments being posted with a registered username, so you won't get into the situation where the anonymous and logged-in usernames are both on the same active comment threads at the same time.

If we prevent it one way, we should prevent it the other. A user could register an account 10 minutes after an anonymous user posts a comment, and then we'd potentially have the same mix of anonymous and logged-in usernames in the same comment thread.

> One option would be some kind of advisory message instead of a hard validation error, but we don't really have a great place to do that.

This is actually something I've previously thought FormAPI should do -- an advisory message that stops form submission once, but then lets you through on the second submit. I may have created an issue for that a long time ago.

andypost’s picture

The only possible confusion could happen if "visitor has no access to user profiles" but for that purpose comment module renders "not verified" after anonymous user names (which is stored as plain text and uid for this comments are always 0)

I'd closed it as works as designed

pameeela’s picture

I am in agreement with catch and andypost that we don’t need to validate usernames against the list of comment names.

There is a bug here (the error on commenting if the anon username is taken) but it will be addressed in #903606: Don't allow users to register with name the same as the Anonymous name. So I still think it’s a duplicate.

‘Show advisory message if a user registers with a name that matches existing comments’ might be a good follow up task. Converting this issue into that would lead to confusion I think.

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.

pameeela’s picture

Status: Needs work » Closed (works as designed)

Since there haven't been any updates to this in 3 years, I'm marking it as closed per the most recent discussion. The other issue is now re-opened and some progress has been made.