You can see the Change Password section of following documentation for this. How to change password in Django.
It works like this:
Navigation to your project where manage.py
file lies
$ python manage.py shell
Execute the following:
from django.contrib.auth.models import User
u = User.objects.get(username__exact='john')
u.set_password('new password')
u.save()
You will have to make a formset and you will perform this action at submission of the form.
You can also use the simple manage.py
command:
manage.py changepassword *username*
Just enter the new password twice.
For second part of your question (User cannot choose old password), you can create a table in which you will store user's old password. When user will enter new password, you can check this in that table whether he can choose it or not. Django has a function check_password which is used to compare two passwords.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…