Fix admin password field corruption and case-sensitive email login - #167
Merged
Conversation
UserAdminForm extended plain ModelForm with fields=__all__, which turned the password column into an editable text input showing the raw hash. Saving any edit there stored plaintext in the password field, making the account impossible to log into (this locked out a real user). Extending django.contrib.auth.forms.UserChangeForm instead renders the password as a ReadOnlyPasswordHashField with a link to the dedicated admin password form, so submitted values are ignored in favor of the stored hash.
EmailBackend matched the login email with a case-sensitive get(email=...), so anyone typing their address with different casing than stored (14 accounts currently have mixed-case emails) was rejected even with a correct password, while password-reset emails still arrived. Switch to email__iexact, falling back to an exact match if case-variant duplicate accounts ever exist (the unique constraint on email is case-sensitive, so they are possible).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two login fixes stemming from the August lockout incident.
1. Admin renders the password as a read-only hash (
56497b1)UserAdminFormextended a plainModelFormwithfields = "__all__", which turned the password column into an editable text input showing the raw hash. If an admin typed a new password into that box, Django stored it as plaintext and the affected user could never log in again (this locked out a real user; the record has since been repaired on the server withset_password). The form now extendsdjango.contrib.auth.forms.UserChangeForm, restoring Django's standard protection: the password renders as a read-only hash summary linking to the dedicated admin password-change form, and submitted values for the field are ignored.2. Case-insensitive email login (
2ef32c2)EmailBackend.authenticatelooked the user up with a case-sensitiveget(email=...). Anyone typing their address with different casing than stored was rejected even with a correct password, while password-reset emails still arrived, a confusing failure mode reported by a real user. 14 current accounts have mixed-case stored emails. The lookup is nowemail__iexact, with a fallback to an exact match in case case-variant duplicate accounts ever exist (the unique constraint on email is case-sensitive, so they are possible; production currently has none).Test plan
UserAdminForm.base_fields["password"]is aReadOnlyPasswordHashField/admin, confirm the password shows as a hash summary with a working "change password" link