Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#27292 closed Cleanup/optimization (fixed)

Example authentication backend doesn't need to set user's password

Reported by: Attila-Mihaly Balazs Owned by: nobody
Component: Documentation Version: 1.10
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Link: https://docs.djangoproject.com/en/1.10/topics/auth/customizing/#writing-an-authentication-backend

It currently says:

...

# Create a new user. Note that we can set password
# to anything, because it won't be checked; the password
# from settings.py will.
user = User(username=username, password='get from settings.py')

....

A better practice would be to call "set_unusable_password()" on the user object.

Attachments (1)

27292.diff (1.4 KB ) - added by Tim Graham 8 years ago.

Download all attachments as: .zip

Change History (5)

comment:1 by Tim Graham, 8 years ago

Could you explain that a bit more? It looks to me like password='get from settings.py' could be password=settings.ADMIN_PASSWORD, but I don't understand why setting an unusable password would be desired.

comment:2 by Tim Graham, 8 years ago

Has patch: set
Summary: Improve example code in the "Writing an authentication backend" of the documentationExample authentication backend doesn't need to set user's password
Triage Stage: UnreviewedAccepted

Proposed patch is attached. Let me know if I missed the reason why set_unusable_password() is useful.

by Tim Graham, 8 years ago

Attachment: 27292.diff added

comment:3 by Tim Graham <timograham@…>, 8 years ago

Resolution: fixed
Status: newclosed

In e262f002:

Fixed #27292 -- Removed unnecessary password assignment in auth backend example.

comment:4 by Tim Graham <timograham@…>, 8 years ago

In 7652f97:

[1.10.x] Fixed #27292 -- Removed unnecessary password assignment in auth backend example.

Backport of e262f002311735869a5d8b0a8f788708322db595 from master

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