#🔒 Flask authentication errors

33 messages · Page 1 of 1 (latest)

tender agate
#

Hi, working with flask right now and not sure why the following code keeps giving back wrong password

rotund stratusBOT
#

@tender agate

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

tender agate
#
@auth_bp.route('/login', methods=['GET', 'POST'])
def login():
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        user = User.query.filter_by(username=username).first()
        if user and check_password_hash(user.password_hash, password):
            session['username'] = username
            return redirect(url_for('home.home_page'))
        return 'Invalid username or password.'
    return render_template('login.html')```
#

Here is my database if needed

#
    username = db.Column(db.String(150), primary_key=True)
    password_hash = db.Column(db.String(500), nullable=False)
    privilege = db.Column(db.Integer, nullable=False)
#

account creation

@auth_bp.route('/register', methods=['GET', 'POST'])
def register():
    if request.method == 'POST':
        username = request.form['username']
        password = request.form['password']
        privilage = request.form['admin']
        if User.query.filter_by(username=username).first():
            return 'Username already exists.'
        hashed_password = generate_password_hash('password', method='pbkdf2')
        new_user = User(username=username, password_hash=hashed_password, privilege=privilage)
        db.session.add(new_user)
        db.session.commit()
        return redirect(url_for('auth.login'))
    return render_template('register.html')```
#

that works fine, using pbkdf2 as on a mac and the newer one does not work correclty

hollow spruce
#

@valid spire why not discuss this here?

tender agate
#

All i see in my sqlite database is this

#

but i know for certain all accounts are there

hollow spruce
tender agate
#

Any you recomend?

hollow spruce
#

I use litecli, but it's a command-line tool.

tender agate
#

how would i use it to list the data in user?

hollow spruce
tender agate
#

okay

#

Now I know the passwords exist

#

@hollow spruce any idea why it wouldn’t be working?

hollow spruce
#

That's using "password" as the password.

tender agate
#

Wdym

#

That is to create an account and put it into the database

#

That all to my knowledge is working fine, the issue is moreso the login

hollow spruce
#

It's ignoring the password sent from the client, and hashing "password".

tender agate
#

Actual?

hollow spruce
tender agate
#

Also how do I get out of litecli

#

Stuck in it rn

hollow spruce
tender agate
#

you beatiful man

#

thank you

rotund stratusBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.