Не знаю, правильно я понял вашу ситуацию или нет. Вот решение, основанное на том, что я понял из вашего вопроса. Вы можете сравнить новый пароль с паролем, который уже используется, используя метод check_password (), который связан с моделью пользователя в Django.
@api_view(['POST'])
def some_function(request):
new_password = request.data.get('password')
# get the user from the request
user_object = request.user
if user_object.check_password(new_password):
# check_password() will hash the new_password in the same way how it hashed the password which is already stored in the db and it will compare the new_password with that password.
print("Both the passwords are same")
else:
print("Passwords are not same")
Если запрос не аутентифицирован, то он не возможно получить пользователя из запроса. В этом случае этот код не будет работать.
Надеюсь, он даст решение вашей проблемы.