Opened 14 years ago

Closed 14 years ago

#15268 closed (invalid)

User.objects.get_or_create has inconsistent behavior

Reported by: w004dal Owned by: nobody
Component: contrib.auth Version: 1.2
Severity: Keywords:
Cc: w004dal@…, w004dal Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When I use User.objects.get_or_create(username=u, password=p) it should be syntactic sugar to:

try:

u = User.objects.get(username=u)
assert u.password == p
return u

except User.DoesNotExist:

return User.objects.create_user(username=u, password=p, email=foo)

Additionally:

User.objects.get_or_create(username=u, password=p) raises a database inconsistency error if 'u' exists with encrypted password 'p'.

If 'u' does not exist in the database, the password is stored in clear text.

This issue seems to coincide with an authentication issue in the administration console. When an admin tries to change the user's password, it is stored in clear text.

Change History (3)

comment:1 by w004dal, 14 years ago

Cc: w004dal added

comment:2 by Russell Keith-Magee, 14 years ago

This isn't inconsistent at all. You create an object with create(). get_or_create() falls back to create().

The User manager provides a helper functions, including 'create_user', to simplify the process of creating a new user -- but to me, that doesn't mean that create_user should be the default used by get_or_create.

comment:3 by Russell Keith-Magee, 14 years ago

Resolution: invalid
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top