Added checks to /import

This commit is contained in:
StNicolay 2022-11-03 10:49:00 +03:00
parent b56ebd0b61
commit 03646b6156
2 changed files with 10 additions and 0 deletions

View File

@ -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")
)

View File

@ -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)