Flask-Web-App-Tutorial icon indicating copy to clipboard operation
Flask-Web-App-Tutorial copied to clipboard

ValueError: Invalid hash method 'sha256'.

Open braydenwny opened this issue 2 years ago • 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")

braydenwny avatar Oct 30 '23 21:10 braydenwny

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

braydenwny avatar Oct 31 '23 17:10 braydenwny

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

WJR1986 avatar Nov 14 '23 12:11 WJR1986

Thank you WJR1986. It works.

TomShare88 avatar Nov 16 '23 22:11 TomShare88

@WJR1986 Bro you're awesome!! thank you

MahdiAlosh avatar Jan 08 '24 20:01 MahdiAlosh

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

Cherisha2023 avatar Jan 15 '24 14:01 Cherisha2023

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

My pleasure! Take care ❤️

WJR1986 avatar Jan 15 '24 15:01 WJR1986

Oh, thank you once again!

On Mon, 15 Jan 2024 at 20:38, William Richardson @.***> wrote:

Thank you so much @WJR1986 https://github.com/WJR1986 I was struggling to find out the error and I found it by your help!

My pleasure! Take care ❤️

— Reply to this email directly, view it on GitHub https://github.com/techwithtim/Flask-Web-App-Tutorial/issues/130#issuecomment-1892348711, or unsubscribe https://github.com/notifications/unsubscribe-auth/BANB3KCJRN6B4NAYD6QRRJDYOVA73AVCNFSM6AAAAAA6WWON3KVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOJSGM2DQNZRGE . You are receiving this because you commented.Message ID: @.***>

Cherisha2023 avatar Jan 15 '24 15:01 Cherisha2023

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

anishvkalbhor avatar Mar 22 '24 19:03 anishvkalbhor

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

ImmortalSheikh avatar Apr 23 '24 14:04 ImmortalSheikh

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

WanjikuKatuni avatar Apr 23 '24 15:04 WanjikuKatuni

Worked like a charm

sethmuriuki avatar May 02 '24 14:05 sethmuriuki

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

creative069 avatar May 17 '24 11:05 creative069

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

My pleasure, buddy. Happy coding ❤️

WJR1986 avatar May 17 '24 18:05 WJR1986

@WJR1986 牛逼 兄弟!

microshark2024 avatar May 30 '24 11:05 microshark2024

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

blCkc0der avatar Jul 26 '24 12:07 blCkc0der

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

Yashvi2410 avatar Aug 06 '24 06:08 Yashvi2410

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

WJR1986 avatar Aug 06 '24 14:08 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'))

May I ask why did you add 'pbkdf2'?

PBKDF2 Explained

Thank you for your reply!

Yashvi2410 avatar Aug 08 '24 05:08 Yashvi2410

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

Adniyi avatar Aug 24 '24 23:08 Adniyi

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

ChibusonmaUdensi avatar Sep 01 '24 23:09 ChibusonmaUdensi