#🔒 Flask authentication errors
33 messages · Page 1 of 1 (latest)
@tender agate
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.
@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
@valid spire why not discuss this here?
All i see in my sqlite database is this
but i know for certain all accounts are there
you can't look at SQLite like that, you need a tool to query the database.
Any you recomend?
I use litecli, but it's a command-line tool.
how would i use it to list the data in user?
the query you want is select * from user
okay
Now I know the passwords exist
@hollow spruce any idea why it wouldn’t be working?
Is this really the line of code?
hashed_password = generate_password_hash('password', method='pbkdf2')
That's using "password" as the password.
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
It's ignoring the password sent from the client, and hashing "password".
Actual?
look: 'password', in quotes.
Try Ctrl-Z if you are on windows, or Ctrl-D otherwise.
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.