How to allow users to change their own passwords in Django?

前端 未结 9 1388
梦如初夏
梦如初夏 2021-01-30 03:57

Can any one point me to code where users can change their own passwords in Django?

9条回答
  •  星月不相逢
    2021-01-30 04:31

    Per the documentation, use:

    from django.contrib.auth.hashers import makepassword
    

    The main reason to do this is that Django uses hashed passwords to store in the database.

    password=make_password(password,hasher='default')
    obj=User.objects.filter(empid=emp_id).update(username=username,password=password)
    

    I used this technique for the custom user model which is derived from the AbstractUser model. I am sorry if I technically misspelled the class and subclass, but the technique worked well.

提交回复
热议问题