Django Admin不散列自定义用户密码 [英] Django Admin Not Hashing Custom User Password

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

问题描述


  • Python 3

  • Django 1.5

  • PostgreSQL 5.0.3

我是Django&的新手。我正在制作一个使用AbstractUser的Django应用,但是当我在Django管理员中创建用户,然后在管理员中查看该用户的信息时,会看到纯文本密码。直接在数据库中检查,我确定密码肯定是以明文形式存储的。

I'm new to Django & I'm making a Django app that makes use of AbstractUser, but when I create a user in the Django admin, and then look at the user's info in the admin, I see the password in plain text. Checking directly in the DB, I see the password is definitely being stored as plaintext.

我正在尝试写一些视图进行身份验证,但是即使用户名和密码正确,它也无法正常工作。所以我猜想 authenticate()函数正在散列,但由于密码实际上没有被散列,所以返回 None

I'm trying to write some views to do some authentication, but it's not working even when the username and password are correct. So I'm guessing that the authenticate() function is hashing but returns None since the password is not actually hashed.

是否有可能未对密码进行哈希处理?

我会发布一些代码,但我认为没有任何代码会有所帮助,因为我的模型不包含任何使用密码字段执行任何操作的代码(这是由Django生成和完成的)。如果我正在做某件事或不做某件事,我什至都不知道代码将包含在代码的哪一部分,因此我必须发布设置,模型,管理等内容。

I'd post some code, but I don't think any code will help, since my model doesn't include any code that does anything with the password field (that's generated & done by Django). If there is something I'm doing or not doing, I wouldn't even know what part of the code it would be in so I'd have to post everything from my settings, models, admin, etc.

推荐答案

我猜问题是您从admin.py中的django.contrib.auth.admin继承了ModelAdmin而不是UserAdmin。

I guess the problem is that you inherited ModelAdmin instead of UserAdmin from django.contrib.auth.admin in your admin.py.

示例代码:

from django.contrib.auth.admin import UserAdmin
from .models import Employee

class EmployeeAdmin(UserAdmin):
    pass

admin.site.register(Employee, EmployeeAdmin)

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

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