Django Admin不对用户密码进行哈希处理 [英] Django Admin not hashing user's password

查看:206
本文介绍了Django Admin不对用户密码进行哈希处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的Django应用程序中使用 AbstractBaseUser UserCreationForm 。通过我的应用程序注册用户时,密码将以哈希格式保存并保存在数据库中。但是,当我尝试使用Django管理网站执行相同操作时,密码将以原始格式保存。

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.

推荐答案

确保您的模型管理员类知道如何对密码进行哈希处理。根据文档,如果使用子类 AbstractBaseUser ,则可以扩展 UserAdmin

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.

假设您的自定义用户模型称为 CustomUser ,则可以尝试以下操作。

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)

这篇关于Django Admin不对用户密码进行哈希处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆