ValueError: Invalid hash method 'sha256'.
braydenwny opened this issue · 21 comments
For some reason whenever I try to hash the password I get this error: ValueError: Invalid hash method 'sha256'. I'm not sure why, as I made sure everything match but just in case here is my code for the auth.py:
from flask import Blueprint, render_template, request, flash, redirect, url_for
from .models import User
from werkzeug.security import generate_password_hash, check_password_hash
from . import db
auth = Blueprint('auth', name)
@auth.route('/login', methods=['GET', 'POST'])
def login():
return render_template("login.html")
@auth.route('/logout')
def logout():
return "
Logout
"@auth.route('/sign-up', methods=['GET', 'POST'])
def sign_up():
if request.method == 'POST':
email = request.form.get('email')
first_name = request.form.get('firstName')
password1 = request.form.get('password1')
password2 = request.form.get('password2')
if len(email) < 4:
flash('Email must be greater than 3 characters', category='error')
elif len(first_name) < 2:
flash('First name must be grater than 1 character', category='error')
elif password1 != password2:
flash('Passwords don\'t match', category='error')
elif len(password1) < 7:
flash('Password must be at least 7 characters', category='error')
else:
new_user = User(email=email, first_name=first_name, password=generate_password_hash(
password1, method='sha256'))
db.session.add(new_user)
db.session.commit()
flash('Account created!', category='success')
return redirect(url_for('views.home'))
return render_template("sign_up.html")
after some googling I found that changing the method from sha256 to scrypt works, so I think sha256 just isn't supported anymore but I'm not 100% sure
update this line:
new_user = User(email=email, first_name=first_name, password=generate_password_hash(password1, method='sha256'))
to this line:
new_user = User(email=email, first_name=first_name, password=generate_password_hash(password1, method='pbkdf2:sha256'))
Thank you WJR1986. It works.
@WJR1986 Bro you're awesome!!
thank you
Thank you so much @WJR1986 I was struggling to find out the error and I found it by your help!
Thank you so much @WJR1986 I was struggling to find out the error and I found it by your help!
My pleasure! Take care ❤️
changing sha256 to scrypt worked for me. maybe 'sha256' is not supported with the latest version.
update this line:
new_user = User(email=email, first_name=first_name, password=generate_password_hash(password1, method='sha256'))
to this line:
new_user = User(email=email, first_name=first_name, password=generate_password_hash(password1, method='pbkdf2:sha256'))
Legend! Thank you so much! Saved me from stressing out
update this line:
new_user = User(email=email, first_name=first_name, password=generate_password_hash(password1, method='sha256'))
to this line:
new_user = User(email=email, first_name=first_name, password=generate_password_hash(password1, method='pbkdf2:sha256'))
This worked thanks
Worked like a charm
Thanks @WJR1986 william for your kind support on this issue . It works ..appreciate your effort ..cheers
Thanks @WJR1986 william for your kind support on this issue . It works ..appreciate your effort ..cheers
My pleasure, buddy. Happy coding ❤️
@WJR1986 牛逼 兄弟!
update this line:
new_user = User(email=email, first_name=first_name, password=generate_password_hash(password1, method='sha256'))
to this line:
new_user = User(email=email, first_name=first_name, password=generate_password_hash(password1, method='pbkdf2:sha256'))
Thanks buddy, your the best. Was already stressing up about this
update this line:
new_user = User(email=email, first_name=first_name, password=generate_password_hash(password1, method='sha256'))
to this line:
new_user = User(email=email, first_name=first_name, password=generate_password_hash(password1, method='pbkdf2:sha256'))
May I ask why did you add 'pbkdf2'?
update this line:
new_user = User(email=email, first_name=first_name, password=generate_password_hash(password1, method='sha256'))
to this line:new_user = User(email=email, first_name=first_name, password=generate_password_hash(password1, method='pbkdf2:sha256'))
May I ask why did you add 'pbkdf2'?
update this line:
new_user = User(email=email, first_name=first_name, password=generate_password_hash(password1, method='sha256'))
to this line:new_user = User(email=email, first_name=first_name, password=generate_password_hash(password1, method='pbkdf2:sha256'))
May I ask why did you add 'pbkdf2'?
Thank you for your reply!
method='pbkdf2:sha256'...use this- 'sha256' is outdated
method='pbkdf2:sha256'...use this- 'sha256' is outdated
One works in this case.