Compare commits

..

5 Commits

3 changed files with 15 additions and 21 deletions

View File

@ -1,12 +1,10 @@
import os import os
from dotenv import load_dotenv from dotenv import load_dotenv
from sqlalchemy.future import Engine
from . import bot, cryptography, database from . import bot, cryptography, database
__all__ = ["bot", "cryptography", "database"] __all__ = ["bot", "cryptography", "database"]
engine: Engine
def main() -> None: def main() -> None:
@ -16,7 +14,7 @@ def main() -> None:
user=os.getenv("DB_USER"), user=os.getenv("DB_USER"),
passwd=os.getenv("DB_PASS"), passwd=os.getenv("DB_PASS"),
db=os.getenv("DB_NAME"), db=os.getenv("DB_NAME"),
) # type: ignore )
database.prepare.prepare(engine) database.prepare.prepare(engine)
bot_ = bot.create_bot(os.getenv("TG_TOKEN"), engine) # type: ignore bot_ = bot.create_bot(os.getenv("TG_TOKEN"), engine)
bot_.infinity_polling() bot_.infinity_polling()

View File

@ -22,9 +22,7 @@ from .utils import (
Message = telebot.types.Message Message = telebot.types.Message
def get_accounts( def get_accounts(bot: telebot.TeleBot, engine: Engine, mes: Message) -> None:
bot: telebot.TeleBot, engine: Engine, mes: telebot.types.Message
) -> None:
base_handler(bot, mes) base_handler(bot, mes)
accounts = database.get.get_accounts(engine, mes.from_user.id) accounts = database.get.get_accounts(engine, mes.from_user.id)
if not accounts: if not accounts:
@ -42,9 +40,7 @@ def get_accounts(
) )
def delete_all( def delete_all(bot: telebot.TeleBot, engine: Engine, mes: Message) -> None:
bot: telebot.TeleBot, engine: Engine, mes: telebot.types.Message
) -> None:
base_handler(bot, mes) base_handler(bot, mes)
bot_mes = bot.send_message( bot_mes = bot.send_message(
mes.chat.id, mes.chat.id,
@ -333,7 +329,7 @@ def _delete_account2(
send_tmp_message(bot, mes.chat.id, "Аккаунт удалён") send_tmp_message(bot, mes.chat.id, "Аккаунт удалён")
def help(bot: telebot.TeleBot, mes: telebot.types.Message) -> None: def help(bot: telebot.TeleBot, mes: Message) -> None:
message = """Команды: message = """Команды:
/set_master_pass - установить мастер пароль /set_master_pass - установить мастер пароль
/add_account - создать аккаунт /add_account - создать аккаунт

View File

@ -11,7 +11,7 @@ from sqlalchemy.future import Engine
from .. import cryptography, database from .. import cryptography, database
class Account(pydantic.BaseModel): class _Account(pydantic.BaseModel):
name: str name: str
login: str login: str
passwd: str passwd: str
@ -25,11 +25,11 @@ class Account(pydantic.BaseModel):
class _Accounts(pydantic.BaseModel): class _Accounts(pydantic.BaseModel):
accounts: list[Account] = pydantic.Field(default_factory=list) accounts: list[_Account] = pydantic.Field(default_factory=list)
def _accounts_list_to_json(accounts: list[tuple[str, str, str]]) -> str: def _accounts_list_to_json(accounts: list[tuple[str, str, str]]) -> str:
accounts = _Accounts(accounts=[Account.from_tuple(i) for i in accounts]) accounts = _Accounts(accounts=[_Account.from_tuple(i) for i in accounts])
return accounts.json() return accounts.json()
@ -106,17 +106,17 @@ def check_account(name: str, login: str, passwd: str) -> bool:
def gen_passwd() -> str: def gen_passwd() -> str:
"""Generates password of length 32""" """Generates password of length 32"""
choices = SystemRandom().choices choices = SystemRandom().choices
chars = frozenset(string.ascii_letters + string.digits + string.punctuation) # Remove backtick and pipe from pucntuation
# Remove backtick and pipe characters and convert into tuple punctuation = set(string.punctuation).difference("`|")
chars = tuple(chars.difference("`|")) chars = tuple(string.ascii_letters + string.digits + "".join(punctuation))
while True: while True:
passwd = "".join(choices(chars, k=32)) passwd = "".join(choices(chars, k=32))
passwd_chars = frozenset(passwd)
# If there is at least one lowercase character, uppercase character # If there is at least one lowercase character, uppercase character
# and one punctuation character # and one punctuation character
if ( if (
passwd_chars.intersection(string.ascii_lowercase) any(c.islower() for c in passwd)
and passwd_chars.intersection(string.ascii_uppercase) and any(c.isupper() for c in passwd)
and passwd_chars.intersection(string.punctuation) and any(c.isdigit() for c in passwd)
and any(c in punctuation for c in passwd)
): ):
return passwd return passwd