Django Admin Not Hashing Custom User Password

前端 未结 3 2084
情深已故
情深已故 2021-02-05 03:44
  • Python 3
  • Django 1.5
  • PostgreSQL 5.0.3

I\'m new to Django & I\'m making a Django app that makes use of AbstractUser, but when I create

3条回答
  •  醉梦人生
    2021-02-05 04:09

    Because it directly save in the database. So before it save you must override the method for hashing the password. Add this in your form:

    def save(self, commit=True):
        # Save the provided password in hashed format
        user = super(MyForm, self).save(commit=False)
        user.set_password(self.cleaned_data["password"])
        if commit:
            user.save()
        return user
    

提交回复
热议问题