Compare commits

...

4 Commits

3 changed files with 13 additions and 18 deletions

View File

@ -1,7 +1,6 @@
import os
from dotenv import load_dotenv
from sqlalchemy.future import Engine
from . import bot, cryptography, database

View File

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

View File

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