Skip to content

Commit

Permalink
Log auth attempts via logging module instead of print statements
Browse files Browse the repository at this point in the history
  • Loading branch information
mepley1 committed Nov 12, 2023
1 parent a0900e8 commit 2db773e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions project/auth.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
""" Authentication routes & functions"""

import datetime #for logging
import logging
import sqlite3 #for logging bad logins
from flask import Blueprint, render_template, redirect, url_for, request, flash
from werkzeug.security import generate_password_hash, check_password_hash
Expand Down Expand Up @@ -76,15 +77,15 @@ def login_post():

# Record the attempt in the database
insert_login_record(username, password)
print('Failed login attempt: ', username)
logging.info(f'Failed login attempt: {username}')

flash('Invalid credentials.', 'errorn')
return redirect(url_for('auth.login')) # if the user doesn't exist or password is wrong, reload the page

# Record the successful login, but obviously don't log the password.
# Can query where password = placeholder later, to query for successful logins.
insert_login_record(username, '*** SUCCESSFUL LOGIN ***')
print('Successful login: ', username)
logging.info(f'Successful login: {username}')
# if the above check passes, then we know the user has the right credentials
login_user(user, remember=remember)
return redirect(url_for('main.stats'))
Expand Down

0 comments on commit 2db773e

Please sign in to comment.