Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why django doesn't save encrypted password?

Tags:

python

django

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
    ...
    ...
like image 445
wasimbhalli Avatar asked Feb 13 '26 23:02

wasimbhalli


1 Answers

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).

like image 118
Alasdair Avatar answered Feb 15 '26 11:02

Alasdair



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!