Compare commits
No commits in common. "267e54bb29ca57a9abab5a335a5f9585a3d53a07" and "4702e048f3c4f0b37e6c4c6e0bb03875f055fa97" have entirely different histories.
267e54bb29
...
4702e048f3
@ -31,8 +31,4 @@ def create_bot(token: str, engine: mariadb.Connection) -> telebot.TeleBot:
|
|||||||
functools.partial(handlers.reset_master_pass, bot, engine),
|
functools.partial(handlers.reset_master_pass, bot, engine),
|
||||||
commands=["reset_master_pass"],
|
commands=["reset_master_pass"],
|
||||||
)
|
)
|
||||||
bot.register_message_handler(
|
|
||||||
functools.partial(handlers.delete_account, bot, engine),
|
|
||||||
commands=["delete_account"],
|
|
||||||
)
|
|
||||||
return bot
|
return bot
|
||||||
|
@ -26,7 +26,7 @@ def add_record(
|
|||||||
|
|
||||||
master_password = data[4]
|
master_password = data[4]
|
||||||
master_password_from_db = database.get.get_master_pass(engine, mes.from_user.id)
|
master_password_from_db = database.get.get_master_pass(engine, mes.from_user.id)
|
||||||
if master_password_from_db is None:
|
if master_password is None:
|
||||||
return _send_tmp_message(bot, mes.chat.id, "Нет мастер пароля")
|
return _send_tmp_message(bot, mes.chat.id, "Нет мастер пароля")
|
||||||
|
|
||||||
master_salt, hash_pass = master_password_from_db
|
master_salt, hash_pass = master_password_from_db
|
||||||
@ -99,14 +99,10 @@ def get_account(
|
|||||||
if len(data) != 3:
|
if len(data) != 3:
|
||||||
return _send_tmp_message(bot, mes.chat.id, "Неправильное количество аргументов")
|
return _send_tmp_message(bot, mes.chat.id, "Неправильное количество аргументов")
|
||||||
|
|
||||||
master_pass = database.get.get_master_pass(engine, mes.from_user.id)
|
|
||||||
if master_pass is None:
|
|
||||||
return _send_tmp_message(bot, mes.chat.id, "Нет мастер пароля")
|
|
||||||
master_salt, hash_pass = master_pass
|
|
||||||
|
|
||||||
if data[1] not in database.get.get_accounts(engine, mes.from_user.id):
|
if data[1] not in database.get.get_accounts(engine, mes.from_user.id):
|
||||||
return _send_tmp_message(bot, mes.chat.id, "Нет такого аккаунта")
|
return _send_tmp_message(bot, mes.chat.id, "Нет такого аккаунта")
|
||||||
|
|
||||||
|
master_salt, hash_pass = database.get.get_master_pass(engine, mes.from_user.id)
|
||||||
if (
|
if (
|
||||||
cryptography.master_pass.encrypt_master_pass_known_salt(data[2], master_salt)
|
cryptography.master_pass.encrypt_master_pass_known_salt(data[2], master_salt)
|
||||||
!= hash_pass
|
!= hash_pass
|
||||||
@ -137,13 +133,6 @@ def reset_master_pass(
|
|||||||
bot: telebot.TeleBot, engine: Engine, mes: telebot.types.Message
|
bot: telebot.TeleBot, engine: Engine, mes: telebot.types.Message
|
||||||
) -> None:
|
) -> None:
|
||||||
data = shlex.split(mes.text)
|
data = shlex.split(mes.text)
|
||||||
if len(data) != 2:
|
|
||||||
return _send_tmp_message(bot, mes.chat.id, "Неправильное количество аргументов")
|
|
||||||
|
|
||||||
master_password_from_db = database.get.get_master_pass(engine, mes.from_user.id)
|
|
||||||
if master_password_from_db is None:
|
|
||||||
return _send_tmp_message(bot, mes.chat.id, "Нет мастер пароля")
|
|
||||||
|
|
||||||
master_password = data[1]
|
master_password = data[1]
|
||||||
enc_pass, salt = cryptography.master_pass.encrypt_master_pass(master_password)
|
enc_pass, salt = cryptography.master_pass.encrypt_master_pass(master_password)
|
||||||
database.delete.purge_accounts(engine, mes.from_user.id)
|
database.delete.purge_accounts(engine, mes.from_user.id)
|
||||||
@ -151,18 +140,3 @@ def reset_master_pass(
|
|||||||
_send_tmp_message(
|
_send_tmp_message(
|
||||||
bot, mes.chat.id, "Все ваши аккаунты удалены, а мастер пароль изменён"
|
bot, mes.chat.id, "Все ваши аккаунты удалены, а мастер пароль изменён"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def delete_account(
|
|
||||||
bot: telebot.TeleBot, engine: Engine, mes: telebot.types.Message
|
|
||||||
) -> None:
|
|
||||||
data = shlex.split(mes.text)
|
|
||||||
bot.delete_message(mes.chat.id, mes.id)
|
|
||||||
|
|
||||||
if len(data) != 2:
|
|
||||||
return _send_tmp_message(bot, mes.chat.id, "Неправильное количество аргументов")
|
|
||||||
|
|
||||||
if data[1] not in database.get.get_accounts(engine, mes.from_user.id):
|
|
||||||
return _send_tmp_message(bot, mes.chat.id, "Нет такого аккаунта")
|
|
||||||
|
|
||||||
database.delete.delete_account(engine, mes.from_user.id, data[1])
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import bcrypt
|
import bcrypt
|
||||||
|
|
||||||
|
print("Hi")
|
||||||
|
|
||||||
|
|
||||||
def encrypt_master_pass(passwd: str) -> tuple[bytes, bytes]:
|
def encrypt_master_pass(passwd: str) -> tuple[bytes, bytes]:
|
||||||
"""Hashes master password and return tuple of hashed password and salt"""
|
"""Hashes master password and return tuple of hashed password and salt"""
|
||||||
|
@ -10,7 +10,7 @@ def change_master_pass(
|
|||||||
statement = sqlmodel.update(
|
statement = sqlmodel.update(
|
||||||
models.MasterPass,
|
models.MasterPass,
|
||||||
models.MasterPass.user_id == user_id,
|
models.MasterPass.user_id == user_id,
|
||||||
{"salt": salt, "passwd": passwd},
|
sqlmodel.values(salt=salt, passwd=passwd),
|
||||||
)
|
)
|
||||||
with sqlmodel.Session(engine) as session:
|
with sqlmodel.Session(engine) as session:
|
||||||
session.exec(statement)
|
session.exec(statement)
|
||||||
|
@ -16,11 +16,3 @@ def delete_master_pass(engine: Engine, user_id: int) -> None:
|
|||||||
)
|
)
|
||||||
with sqlmodel.Session(engine) as session:
|
with sqlmodel.Session(engine) as session:
|
||||||
session.exec(statement)
|
session.exec(statement)
|
||||||
|
|
||||||
|
|
||||||
def delete_account(engine: Engine, user_id: int, name: str) -> None:
|
|
||||||
statement = sqlmodel.delete(models.Account).where(
|
|
||||||
models.Account.user_id == user_id and models.Account.name == name
|
|
||||||
)
|
|
||||||
with sqlmodel.Session(engine) as session:
|
|
||||||
session.exec(statement)
|
|
||||||
|
@ -11,6 +11,7 @@ def get_master_pass(engine: Engine, user_id: int) -> tuple[bytes, bytes] | None:
|
|||||||
)
|
)
|
||||||
with sqlmodel.Session(engine) as session:
|
with sqlmodel.Session(engine) as session:
|
||||||
result = session.exec(statement).first()
|
result = session.exec(statement).first()
|
||||||
|
print(result)
|
||||||
if result is None:
|
if result is None:
|
||||||
return
|
return
|
||||||
return (result.salt, result.passwd)
|
return (result.salt, result.passwd)
|
||||||
|
@ -8,6 +8,7 @@ def get_engine(host: str, user: str, passwd: str, db: str) -> Engine:
|
|||||||
engine = sqlmodel.create_engine(
|
engine = sqlmodel.create_engine(
|
||||||
f"mariadb+mariadbconnector://{user}:{passwd}@{host}/{db}"
|
f"mariadb+mariadbconnector://{user}:{passwd}@{host}/{db}"
|
||||||
)
|
)
|
||||||
|
print(type(engine))
|
||||||
return engine
|
return engine
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user