From 62651f981fa6ac6c87ab95b8e52eeca60e80ed6a Mon Sep 17 00:00:00 2001 From: lonkaars Date: Mon, 26 Apr 2021 11:28:22 +0200 Subject: update username/email endpoints --- api/auth/login.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'api/auth') diff --git a/api/auth/login.py b/api/auth/login.py index e3d5fde..e0cb406 100644 --- a/api/auth/login.py +++ b/api/auth/login.py @@ -3,6 +3,14 @@ from db import cursor import auth.token as token import passwords +def login_password(user_id, password): + passwd_hash = cursor.execute( + "select password_hash from users where user_id = ?", [user_id] + ).fetchone() + if not passwd_hash: return False + check = passwords.check_password(password, passwd_hash[0]) + return bool(check) + login = Blueprint('login', __name__) @@ -29,11 +37,8 @@ def index(): if user_id == None: return "", 401 # check the password - passwd = cursor.execute( - "select password_hash from users where user_id = ?", [user_id[0]] - ).fetchone() - check = passwords.check_password(password, passwd[0]) - if not check: return "", 401 + valid_password = login_password(user_id[0], password) + if not valid_password: return "", 401 # generate a new authentication token and add it to the users valid token list new_token = token.generate_token() -- cgit v1.2.3