From 03646b61565371751c6fa9699a8b6035f8d45e41 Mon Sep 17 00:00:00 2001 From: StNicolay Date: Thu, 3 Nov 2022 10:49:00 +0300 Subject: [PATCH] Added checks to /import --- src/bot/handlers.py | 5 +++++ src/bot/utils.py | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/src/bot/handlers.py b/src/bot/handlers.py index 816005e..c3b17a0 100644 --- a/src/bot/handlers.py +++ b/src/bot/handlers.py @@ -12,6 +12,7 @@ from .utils import ( check_account_name, check_login, check_passwd, + check_account, get_all_accounts, json_to_accounts, send_tmp_message, @@ -437,9 +438,13 @@ def _import3( if cryptography.master_pass.encrypt_master_pass(text, master_salt) != hash_pass: return send_tmp_message(bot, mes.chat.id, "Не подходит мастер пароль") + # List of names of accounts, which failed to be added to the database or failed tests failed: list[str] = [] for account in accounts: name, login, passwd = account + if not check_account(name, login, passwd): + failed.append(name) + continue enc_login, enc_passwd, salt = cryptography.other_accounts.encrypt_account_info( login, passwd, text.encode("utf-8") ) diff --git a/src/bot/utils.py b/src/bot/utils.py index 0548eff..7297b0e 100644 --- a/src/bot/utils.py +++ b/src/bot/utils.py @@ -95,3 +95,8 @@ def check_login(login: str) -> bool: def check_passwd(passwd: str) -> bool: "Returns true if password is valid" return _base_check(passwd) + + +def check_account(name: str, login: str, passwd: str) -> bool: + """Runs checks for account name, login and password""" + return check_account_name(name) and check_login(login) and check_passwd(passwd)