techwithtim / Flask-Web-App-Tutorial

Code for the note storing flask web app made during a YouTube video.
918 stars 1.01k forks source link

ValueError: Invalid hash method 'sha256'. #130

Open braydenwny opened 10 months ago

braydenwny commented 10 months ago

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 commented 10 months ago

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 commented 9 months ago

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 commented 9 months ago

Thank you WJR1986. It works.

MahdiAlosh commented 8 months ago

@WJR1986 Bro you're awesome!! thank you

Cherisha2023 commented 7 months ago

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

WJR1986 commented 7 months ago

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 commented 7 months ago

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: @.***>

anishvkalbhor commented 5 months ago

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

ImmortalSheikh commented 4 months ago

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 commented 4 months ago

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 commented 4 months ago

Worked like a charm

creative069 commented 3 months ago

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

WJR1986 commented 3 months ago

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

My pleasure, buddy. Happy coding ❤️

microshark2024 commented 3 months ago

@WJR1986 牛逼 兄弟!

blCkc0der commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 1 month ago

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 commented 2 weeks ago

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

ChibusonmaUdensi commented 6 days ago

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