Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueError: Invalid hash method 'sha256'. #130

Open
braydenwny opened this issue Oct 30, 2023 · 21 comments
Open

ValueError: Invalid hash method 'sha256'. #130

braydenwny opened this issue Oct 30, 2023 · 21 comments

Comments

@braydenwny
Copy link

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")
@braydenwny
Copy link
Author

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

@WJR1986
Copy link

WJR1986 commented Nov 14, 2023

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'))

@TomShare88
Copy link

Thank you WJR1986. It works.

@MahdiAlosh
Copy link

@WJR1986 Bro you're awesome!!
thank you

@Cherisha2023
Copy link

Thank you so much @WJR1986 I was struggling to find out the error and I found it by your help!

@WJR1986
Copy link

WJR1986 commented Jan 15, 2024

Thank you so much @WJR1986 I was struggling to find out the error and I found it by your help!

My pleasure! Take care ❤️

@Cherisha2023
Copy link

Cherisha2023 commented Jan 15, 2024 via email

@anishvkalbhor
Copy link

changing sha256 to scrypt worked for me. maybe 'sha256' is not supported with the latest version.

@ImmortalSheikh
Copy link

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

@WanjikuKatuni
Copy link

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

@sethmuriuki
Copy link

Worked like a charm

@creative069
Copy link

Thanks @WJR1986 william for your kind support on this issue . It works ..appreciate your effort ..cheers

@WJR1986
Copy link

WJR1986 commented May 17, 2024

Thanks @WJR1986 william for your kind support on this issue . It works ..appreciate your effort ..cheers

My pleasure, buddy. Happy coding ❤️

@microshark2024
Copy link

@WJR1986 牛逼 兄弟!

@blCkc0der
Copy link

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

@Yashvi2410
Copy link

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'?

@WJR1986
Copy link

WJR1986 commented Aug 6, 2024

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'?

PBKDF2 Explained

@Yashvi2410
Copy link

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'?

PBKDF2 Explained

Thank you for your reply!

@Adniyi
Copy link

Adniyi commented Aug 24, 2024

@WJR1986 Thank you so much 😊🙏. You were of great help

@ChibusonmaUdensi
Copy link

method='pbkdf2:sha256'...use this- 'sha256' is outdated

@WJR1986
Copy link

WJR1986 commented Oct 12, 2024

method='pbkdf2:sha256'...use this- 'sha256' is outdated

One works in this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests