This repository has been archived on 2023-08-08. You can view files and clone it, but cannot push or open issues or pull requests.
PassManager/src/database/add.py

41 lines
1.0 KiB
Python
Raw Normal View History

2022-10-14 12:38:03 +00:00
import sqlmodel
2022-10-05 12:04:39 +00:00
import mariadb
2022-10-14 12:38:03 +00:00
from sqlalchemy.future import Engine
from . import models
2022-10-05 12:04:39 +00:00
2022-09-29 13:02:11 +00:00
2022-10-14 12:38:03 +00:00
def add_account(
engine: Engine,
user_id: int,
name: str,
salt: bytes,
enc_login: bytes,
enc_pass: bytes,
2022-10-05 11:44:03 +00:00
) -> bool:
2022-10-14 12:41:55 +00:00
"""Adds account to db. Returns true, if on success"""
2022-10-14 12:38:03 +00:00
account = models.Account(
user_id=user_id, name=name, salt=salt, enc_login=enc_login, enc_pass=enc_pass
)
2022-10-05 11:52:23 +00:00
try:
2022-10-14 12:38:03 +00:00
with sqlmodel.Session(engine) as session:
session.add(account)
session.commit()
2022-10-05 11:52:23 +00:00
except Exception:
return False
else:
return True
2022-09-29 13:02:11 +00:00
2022-10-14 12:38:03 +00:00
def add_master_pass(engine: Engine, user_id: int, salt: bytes, passwd: bytes) -> bool:
2022-10-14 12:41:55 +00:00
"""Adds master password to db. Returns true, if on success"""
2022-10-14 12:38:03 +00:00
master_pass = models.MasterPass(user_id=user_id, salt=salt, passwd=passwd)
2022-10-05 11:52:23 +00:00
try:
2022-10-14 12:38:03 +00:00
with sqlmodel.Session(engine) as session:
session.add(master_pass)
session.commit()
2022-10-05 11:52:23 +00:00
except Exception:
return False
else:
return True