为什么django不保存加密密码? [英] Why django doesn't save encrypted password?

查看:186
本文介绍了为什么django不保存加密密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用django 1.4。创建新用户时,会保存纯密码。是否有一个设置,所以当保存用户时,密码保存加密?



编辑



我只是使用内置的管理功能添加一个用户。没有什么花哨 - 只是内置的验证模块和在管理员中自动创建的用户表单。






更多编辑



我需要一些自定义字段,因此我使用了一个自定义类:

  class UserForm(forms.ModelForm):
class Meta:
model = User
...
...


解决方案

您应该使用 create_user 管理员方法创建用户时。



如果您要创建自定义表单,请将 UserCreationForm UserChangeForm 。如果您正在创建自定义的 ModelAdmin ,那么子类 UserAdmin 。否则,您将不得不自行重新实现密码散列功能。



请注意,密码将被散列,而不是加密(即您无法解密)。


I've using django 1.4. When creating a new user, it saves plain password. Is there a setting for it so when saving a user, the password is saved encrypted?

EDIT

I'm simply using the built-in admin functionality to add a user. Nothing fancy - just the built in auth module and the user form that is automatically created in admin.


More Edit

I required some custom field so I've used a custom class:

class UserForm(forms.ModelForm):
    class Meta:
        model = User
    ...
    ...

解决方案

You should use the create_user manager method when creating users.

If you're creating custom forms, subclass one of the UserCreationForm or UserChangeForm. If you're creating a custom ModelAdmin, then subclass UserAdmin. Otherwise you'll have to re-implement the password hashing functionality yourself.

Note that the password will be hashed, not encrypted (i.e. you can't decrypt it).

这篇关于为什么django不保存加密密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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