I have encountered an issue in the admin panel of my application. When creating a new user and setting the password, the password is displayed in plain text.
Here is a brief description of the problem:
- Navigate to the admin panel.
- Select the option to create a new user.
- Enter a password for the new user.
Expected behavior:
The password should be hidden and displayed as dots or asterisks (e.g., ********).
Actual behavior:
The password is displayed in plain text, which poses a security risk.
Could someone guide me on how to modify the admin panel so that the password is not displayed in plain text?
That didn’t help either
Link
admin.py
from django.contrib import admin
from django.contrib.auth.hashers import make_password
from user import models
class UserAdmin(admin.ModelAdmin):
"""Define the admin pages for users."""
ordering = ['id']
list_display = ['id', 'email', 'name']
search_fields = ['id', 'name', 'email']
readonly_fields = ['last_login']
def save_model(self, request, obj, form, change):
obj.password = make_password(obj.password)
obj.user = request.user
obj.save()
# Register your models here.
admin.site.register(models.User, UserAdmin)