Opened 20 months ago

Closed 9 months ago

Last modified 3 months ago

#34429 closed New feature (fixed)

Allow to set unusable password via admin UI

Reported by: Tobias Bengfort Owned by: Fabian Braun
Component: contrib.auth Version: dev
Severity: Normal Keywords:
Cc: Carlton Gibson, Sarah Boyce Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: yes

Description (last modified by Fabian Braun)

Django allows to have user accounts with unusable passwords, either because authentication uses a different mechanism (e.g. LDAP) or because the User object is still needed (e.g. because it is referenced by a ForeignKey) but the user should no longer be allowed to log in.

However, this functionality is not available from the admin UI. When creating a user or changing the password I am forced to enter a password.

I propose to make the password fields optional in the Admin UI and set an unusable password if they are blank.

I am sorry if this has been discussed before. I looked before posting this but could not find anything.

PR

Change History (19)

comment:1 by Mariusz Felisiak, 20 months ago

Triage Stage: UnreviewedAccepted
Version: 4.1dev

Thanks for the ticket. I agree that it would nice to add an option to create users with an unusable password in the admin, however, any implicit logic can be confusing here (see comment). Therefore, I'm not in favor of your proposal to:

... make the password fields optional in the Admin UI and set an unusable password if they are blank.

Maybe a checkbox in the "Add user" form e.g. "Usable password" (checked by default) that would hide password fields when unchecked 🤔, or sth similar.

Tentatively accepted.

comment:2 by Mariusz Felisiak, 20 months ago

Cc: Carlton Gibson Sarah Boyce added

comment:3 by SAHIL SANJAY CHALKE, 20 months ago

Owner: changed from nobody to SAHIL SANJAY CHALKE
Status: newassigned

comment:4 by SAHIL SANJAY CHALKE, 20 months ago

i am starting to work on the project

comment:5 by Fabian Braun, 18 months ago

Owner: changed from SAHIL SANJAY CHALKE to Fabian Braun

comment:6 by Fabian Braun, 18 months ago

Have a working solution. Will add tests and create a PR.

The checkbox field is called "Allow login" to clearly indicate that users w/o password will not be able to log in. Please let me know if "Usable password" is deemed a better label.

The password fields are only visible and validated if the checkbox is set.

comment:7 by Fabian Braun, 18 months ago

Description: modified (diff)
Has patch: set

comment:8 by Nick Pope, 18 months ago

Needs documentation: set
Patch needs improvement: set

comment:9 by Fabian Braun, 18 months ago

Needs documentation: unset
Patch needs improvement: unset

comment:10 by Fabian Braun, 18 months ago

UI/UX: set

comment:11 by Mariusz Felisiak, 17 months ago

Needs tests: set
Patch needs improvement: set

comment:12 by Sarah Boyce, 16 months ago

Needs tests: unset
Patch needs improvement: unset

comment:13 by Natalia Bidart, 12 months ago

Patch needs improvement: set

Made many rounds of reviews, including a great conversation about UX of this feature (see Discord chat).

comment:14 by Natalia Bidart, 9 months ago

Triage Stage: AcceptedReady for checkin

Multiple round of reviews later, and some further UI/UX, tests and docs tweaks, this is ready for checkin! \o/

comment:15 by Natalia <124304+nessita@…>, 9 months ago

In f64c528:

Refs #34429 -- Created SetPasswordMixin to reuse password validation logic in auth forms.

Co-authored-by: Natalia <124304+nessita@…>

comment:16 by Natalia <124304+nessita@…>, 9 months ago

In 8a75724:

Refs #34429 -- Defined test user with unusable password for auth forms tests.

comment:17 by Natalia <124304+nessita@…>, 9 months ago

Resolution: fixed
Status: assignedclosed

In e626716c:

Fixed #34429 -- Allowed setting unusable passwords for users in the auth forms.

Co-authored-by: Natalia <124304+nessita@…>

comment:18 by nessita <124304+nessita@…>, 3 months ago

In 0ebed5f:

Fixed #35678 -- Removed "usable_password" field from BaseUserCreationForm.

Refs #34429: Following the implementation allowing the setting of
unusable passwords via the admin site, the BaseUserCreationForm and
UserCreationForm were extended to include a new field for choosing
whether password-based authentication for the new user should be enabled
or disabled at creation time.
Given that these forms are designed to be extended when implementing
custom user models, this branch ensures that this new field is moved to
a new, admin-dedicated, user creation form AdminUserCreationForm.

Regression in e626716c28b6286f8cf0f8174077f3d2244f3eb3.

Thanks Simon Willison for the report, Fabian Braun and Sarah Boyce for
the review.

comment:19 by Natalia <124304+nessita@…>, 3 months ago

In da22e6cb:

[5.1.x] Fixed #35678 -- Removed "usable_password" field from BaseUserCreationForm.

Refs #34429: Following the implementation allowing the setting of
unusable passwords via the admin site, the BaseUserCreationForm and
UserCreationForm were extended to include a new field for choosing
whether password-based authentication for the new user should be enabled
or disabled at creation time.
Given that these forms are designed to be extended when implementing
custom user models, this branch ensures that this new field is moved to
a new, admin-dedicated, user creation form AdminUserCreationForm.

Regression in e626716c28b6286f8cf0f8174077f3d2244f3eb3.

Thanks Simon Willison for the report, Fabian Braun and Sarah Boyce for
the review.

Backport of 0ebed5fa95f53b87383901bbd9341ef3c974344f from main.

Note: See TracTickets for help on using tickets.
Back to Top