pbms
pbms

Reputation: 633

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?

Upvotes: 1

Views: 89

Answers (1)

pbms
pbms

Reputation: 633

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)

Upvotes: 1

Related Questions