Search code examples
python-3.xadmindjango-1.11

creating user through admin panel password is not hashing


I have logged in to admin panel as superuser, I want to create new user through admin panel , After creating new user with raw password is not hashing in admin panel. Its showing raw password. How to hash the password while creating user through admin panel?


Solution

  • override password method, In admin.py

     class PasswordUserAdmin(admin.ModelAdmin): 
        def save_model(self, request, obj, form, change):
           obj.password= make_password(obj.password)
           obj.user = request.user
           obj.save()
    

    add this class in site.register

     admin.site.register(User, PasswordUserAdmin)