djangodjango-admin

Django Admin not hashing user's password


I am using AbstractBaseUser and UserCreationForm with my Django app. When registering users through my app, the password gets saved in hash format and saved in the database. But when I try to do the same thing using Django admin site, the password gets saved in raw format.


Solution

  • You need to make sure that your model admin class knows how to hash passwords. According to the docs, if you are using subclassing AbstractBaseUser, then you might be able to extend UserAdmin.

    Assuming your custom user model is called CustomUser, you could try the following.

    from django.contrib.auth.admin import UserAdmin
    
    class CustomUserAdmin(UserAdmin):
        ...
    
    admin.site.register(CustomUser, CustomUserAdmin)