Flask - Resolve "The 'sha256' password method is deprecated and will be removed in Werkzeug 3.0. Migrate to the 'scrypt' method."
by
Jeremy Canfield |
Updated: December 18 2023
| Flask articles
Let's say something like this is being returned.
UserWarning: The 'sha256' password method is deprecated and will be removed in Werkzeug 3.0. Migrate to the 'scrypt' method.
I first got this when using werkzeug.securitty generate_password_hash, perhaps something like this. Notice in this example that generate_password_hash has method='sha256'.
from flask import Blueprint, render_template
from sqlalchemy import func
from . import db
from .models import users
from werkzeug.security import generate_password_hash
views = Blueprint('views', __name__)
@views.route('/')
def home():
data = users(
username='john.doe',
password=generate_password_hash('itsasecret', method='sha256'),
date_updated=func.now()
)
db.session.add(data)
db.session.commit()
return render_template('home.html')
Simply replace sha256 with scrypt.
from flask import Blueprint, render_template
from sqlalchemy import func
from . import db
from .models import users
from werkzeug.security import generate_password_hash
views = Blueprint('views', __name__)
@views.route('/')
def home():
data = users(
username='john.doe',
password=generate_password_hash('itsasecret', method='scrypt'),
date_updated=func.now()
)
db.session.add(data)
db.session.commit()
return render_template('home.html')
Did you find this article helpful?
If so, consider buying me a coffee over at