Created get.py

This commit is contained in:
StNicolay 2022-09-29 15:58:56 +03:00
parent 89d8e78eec
commit c8410a877c

31
src/database/get.py Normal file
View File

@ -0,0 +1,31 @@
import mariadb
def get_master_pass(con: mariadb.Connection, id: int) -> tuple[bytes, bytes]:
"""Returns tuple of salt and hashed master password"""
cursor = con.cursor()
cursor.execute("SELECT salt, passwd FROM master_pass IF user_id = ?", [id])
result = cursor.fetchone()
cursor.close()
return result
def get_accounts(con: mariadb.Connection, id: int) -> list[str]:
"""Returns list of user accounts"""
cursor = con.cursor()
cursor.execute("SELECT acc_name FROM accounts IF user_id = ?", [id])
return [i[0] for i in cursor.fetchall()]
def get_account_info(
id: int, name: str, con: mariadb.Connection
) -> tuple[bytes, bytes, bytes]:
"""Returns tuple of salt, login and password"""
cursor = con.cursor()
cursor.execute(
"""SELECT salt, enc_login, enc_pass IF user_id = ? AND acc_name = ?""",
[id, name],
)
result = cursor.fetchone()
cursor.close()
return result