aboutsummaryrefslogtreecommitdiff
path: root/api/util/validate_login_information.py
blob: 55bbb2e9789e64001c8f7d984d4925c5a976b125 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import bcrypt
from fastapi import Depends

from api.util.db_dependency import get_db
from models import User

"""
Validate the login information provided by the user
"""


def validate_login_information(
    username: str, password: str, db=Depends(get_db)
) -> bool:
    user = db.query(User).filter(User.username == username).first()
    if not user:
        return False
    if bcrypt.checkpw(password.encode("utf-8"), user.password.encode("utf-8")):
        return True
    return False