How do I update the password?

Question:

I am working on a web app and I want a user to be able to reset their password but I’m failing to do so how can I do it?

I also tried

email = request.form.get('email')
new_password = request.form.get('password')

user = User.query.filter_by(email=email).first()
If user :
user.password = new_password. #The new_password 
Asked By: Brandon Khumalo

||

Answers:

I think below should work for your requirements

Here you are getting the user by filtering , you can get the user instance or you can also current logged in user as that will be the one you’ll updating password for, and you can update password like this

from flask import Flask, session
flask_login.current_user #current user

### or get the user_id just like 
user_id = session["user_id"]

user = User.objects.get(id=user_id)
user.modify(password=password)
user.hash_password()
user.save()
Answered By: madara_was_right