When registering or editing a user, if you enter 0 in the password field, you'll get a form error Password field is required.

Although '0' is a terrible password, it should be valid input as far as this form is concerned, so the error is wrong.

If you created the user with password '0', you can't log in with that user.

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Bug because the form error is wrong.
Issue priority Normal, because 0 is the worst password in the world.
Prioritized changes The main goal of this issue is to fix a bug—a confusing form error.
CommentFileSizeAuthor
#29 2563751-29.patch4.86 KBpietmarcus
#23 Error in Login: Before patch.jpg77.02 KBNikitaJain
#23 Edit account set password '0' : Before patch.jpg95.37 KBNikitaJain
#23 Create new account: Before Patch.jpg81.28 KBNikitaJain
#23 My Account.png117.39 KBNikitaJain
#23 Successfull login.png142.9 KBNikitaJain
#23 User Login with passowrd '0'.png125.32 KBNikitaJain
#22 password_field_errors-2563751-19.patch7.89 KBborisson_
#20 My Account: After Patch.jpg64.12 KBNikitaJain
#20 Successfully login : After patch.jpg69.2 KBNikitaJain
#20 Login with new user & password '0' : After patch.jpg67.47 KBNikitaJain
#20 Edit user password set to '0': After patch.jpg97.76 KBNikitaJain
#20 User added : After patch.jpg89.85 KBNikitaJain
#20 Create new account: After patch.jpg84.6 KBNikitaJain
#20 Error in Login: Before patch.jpg77.02 KBNikitaJain
#20 Edit account set password '0' : Before patch.jpg95.37 KBNikitaJain
#20 New user added - Before patch.jpg89.75 KBNikitaJain
#20 Create new account: Before Patch.jpg81.28 KBNikitaJain
#19 password_field_errors-2563751-19.patch7.89 KBborisson_
#19 interdiff.txt1.06 KBborisson_
#18 password_field_errors-2563751-18.patch6.83 KBrocketeerbkw
#18 interdiff.txt2.2 KBrocketeerbkw
#15 can_t_create_a_user_or-2563751-15.patch4.63 KBborisson_
#15 interdiff-3-15.txt2.85 KBborisson_
#15 interdiff.txt1.33 KBborisson_
#14 can_t_create_a_user-2563751-14.patch3.29 KBborisson_
#14 interdiff.txt1.51 KBborisson_
#3 can_t_create_a_user-2563751-3.patch1.78 KBcilefen
#3 can_t_create_a_user-2563751-3-FAIL.patch998 bytescilefen
#2 2563751-2.patch822 bytesrocketeerbkw
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rocketeerbkw created an issue. See original summary.

rocketeerbkw’s picture

Status: Active » Needs review
FileSize
822 bytes

This is because \Drupal\Core\Render\Element\PasswordConfirm uses empty() which treats 0 as falsey.

I changed it to strlen() > 0.

cilefen’s picture

cilefen’s picture

Issue tags: +Needs backport to D7

The last submitted patch, 3: can_t_create_a_user-2563751-3-FAIL.patch, failed testing.

cilefen’s picture

Issue tags: +Novice, +Quick fix
rocketeerbkw’s picture

Assigned: rocketeerbkw » Unassigned

Removing myself so anyone can feel free to take on the novice part.

cilefen’s picture

The novice task is to offer a review.

+++ b/core/modules/user/src/Tests/UserCreateTest.php
@@ -114,5 +114,19 @@ public function testUserAdd() {
+    $edit = array(
+      'name' => $name,
+      'mail' => $this->randomMachineName() . '@example.com',
+      'pass[pass1]' => 0,
+      'pass[pass2]' => 0,
+      'notify' => FALSE,
+    );

I wonder if the zeros in the form steps should be quoted as strings.

ieguskiza’s picture

Assigned: Unassigned » ieguskiza
ieguskiza’s picture

Issue tags: +DUGBE0609
ieguskiza’s picture

Hi,
revised both patches on a fresh D8 install:
- Confirmed that fail test actually fails.
- Confirmed that the test after applying the patch passes correctly.

Apt to be labeled as RTBC

Regards,
Imanol

ieguskiza’s picture

Assigned: ieguskiza » Unassigned
Anonymous’s picture

Status: Needs review » Needs work

The patch looks good, and manually testing revealed that I'm able to create a user with password 0. However, I'm not able to log-in. So back to needs work to investigate that.

As for #8, I'm not sure, but I'd think you should add the quotes.

borisson_’s picture

Title: Can't create a user when password is (literally) 0 » Can't create a user (or login with that user) when password is (literally) 0
Issue summary: View changes
Status: Needs work » Needs review
FileSize
1.51 KB
3.29 KB

You can now log in with that user. UserAuth also used empty($password), changed that to strlen as well.

borisson_’s picture

Added a test for UserAuth to prevent regressions.

Anonymous’s picture

Status: Needs review » Reviewed & tested by the community

I manually verified that creating a user with password 0 is allowed, and that such a user can login.

The tests seem good to me, we have a beta eval and IS is up to date. So RTBC.

rocketeerbkw’s picture

Title: Can't create a user (or login with that user) when password is (literally) 0 » Password field errors on user create/edit/login when password is (literally) 0
Assigned: Unassigned » rocketeerbkw
Status: Reviewed & tested by the community » Needs work

The "current password" on edit user form also errors on 0. I'm working on a patch for that too.

rocketeerbkw’s picture

Assigned: rocketeerbkw » Unassigned
FileSize
2.2 KB
6.83 KB

I fixed the "Current password" AND pass/confirm pass fields on edit user page but it needs tests for both those scenarios.

borisson_’s picture

Status: Needs work » Needs review
FileSize
1.06 KB
7.89 KB

Added a test for the pass/confirm fields on user edit.

NikitaJain’s picture

Tested this patch password_field_errors-2563751-19.patch. It works fine. Manually verified that I am able to create a user with password 0 and able to login with same password after applying the patch. Screenshots attached.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 19: password_field_errors-2563751-19.patch, failed testing.

borisson_’s picture

Status: Needs work » Needs review
FileSize
7.89 KB

I don't think the failures in #19 are related to this issue, They're all installer related and this doesn't touch Installer code.

I uploaded the patch from #19 again here. If this passes I think it can go back to RTBC (per #20)

NikitaJain’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
125.32 KB
142.9 KB
117.39 KB
81.28 KB
95.37 KB
77.02 KB

Tested password_field_errors-2563751-19_0.patch on Firefox and chrome for Ubuntu 14.04. It works fine. Manually verified that creating a user with password '0' is allowed and user can able to login successfully with same password after applying the patch.
Screenshots attached.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

This is a funny issue and obviously no one should have a password of 0 but 0 is just as valid as 1. Committed fb8e894 and pushed to 8.0.x. Thanks!

  • alexpott committed fb8e894 on 8.0.x
    Issue #2563751 by borisson_, rocketeerbkw, cilefen, NikitaJain, imanol....
cilefen’s picture

Version: 8.0.x-dev » 7.x-dev
Status: Fixed » Patch (to be ported)

  • alexpott committed fb8e894 on 8.1.x
    Issue #2563751 by borisson_, rocketeerbkw, cilefen, NikitaJain, imanol....
pietmarcus’s picture

Assigned: Unassigned » pietmarcus

I'll backport this issue to drupal 7.

pietmarcus’s picture

Status: Patch (to be ported) » Needs review
FileSize
4.86 KB

Managed to port it to Drupal 7. Automatic and manual tests all worked. Please review!

Revathi.B’s picture

Issue tags: +#ChennaiDrupalGroup

Tested 2563751-29.patch.It works great.thanks for the patch.

Revathi.B’s picture

Status: Needs review » Reviewed & tested by the community

Hi pietmarcus,
Your patch works great as per our need.

Pradnya Pingat’s picture

worked fine.

Pradnya Pingat’s picture

Assigned: pietmarcus » Pradnya Pingat
Pradnya Pingat’s picture

Assigned: Pradnya Pingat » Unassigned
Fabianx’s picture

Issue tags: +Pending Drupal 7 commit

There is a lot of mismatch of using trim() + strlen() and only using strlen(), but D8 has the same and sync of code is more important to me.

I think we make it impossible to use " " as password now. But I think empty was empty before, so its not a regression and " " might indeed be considered as fill out the password field ...

Marked for commit.

David_Rothstein’s picture

Status: Reviewed & tested by the community » Fixed
Issue tags: -Pending Drupal 7 commit

Yeah, at least when you create a user account via the UI a password of " " seems like it's blocked already, so I think that's OK. And if we're wrong and this issue results in blocking the ability of someone who actually has a password of " " from logging in, that's not a bad thing since they really should change their password anyway :)

I removed the following on commit, since we don't reference issues like that unless there's a very specific reason to do so (I realize the Drupal 8 tests have this too, but it's only a code comment change and can be removed in Drupal 8 later if desired):

diff --git a/modules/user/user.test b/modules/user/user.test
index bcb92c1..92901b4 100644
--- a/modules/user/user.test
+++ b/modules/user/user.test
@@ -1879,7 +1879,6 @@ class UserCreateTestCase extends DrupalWebTestCase {
     }
 
     // Test that the password '0' is considered a password.
-    // @see https://www.drupal.org/node/2563751.
     $name = $this->randomName();
     $edit = array(
       'name' => $name,
@@ -1971,10 +1970,6 @@ class UserEditTestCase extends DrupalWebTestCase {
 
   /**
    * Tests setting the password to "0".
-   *
-   * We discovered in https://www.drupal.org/node/2563751 that logging in with a
-   * password that is literally "0" was not possible. This test ensures that
-   * this regression can't happen again.
    */
   public function testUserWith0Password() {
     $admin = $this->drupalCreateUser(array('administer users'));

Status: Fixed » Closed (fixed)

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