Added account name and account credential checking
This commit is contained in:
parent
adf9865fbe
commit
b56ebd0b61
@ -9,6 +9,9 @@ from .. import cryptography, database
|
||||
from .utils import (
|
||||
accounts_to_json,
|
||||
base_handler,
|
||||
check_account_name,
|
||||
check_login,
|
||||
check_passwd,
|
||||
get_all_accounts,
|
||||
json_to_accounts,
|
||||
send_tmp_message,
|
||||
@ -139,6 +142,8 @@ def _add_account2(
|
||||
if text == "/cancel":
|
||||
return send_tmp_message(bot, mes.chat.id, "Успешная отмена")
|
||||
|
||||
if not check_account_name(text):
|
||||
return send_tmp_message(bot, mes.chat.id, "Не корректное название аккаунта")
|
||||
if text in database.get.get_accounts(engine, mes.from_user.id):
|
||||
return send_tmp_message(
|
||||
bot, mes.chat.id, "Аккаунт с таким именем уже существует"
|
||||
@ -163,6 +168,8 @@ def _add_account3(
|
||||
text = mes.text.strip()
|
||||
if text == "/cancel":
|
||||
return send_tmp_message(bot, mes.chat.id, "Успешная отмена")
|
||||
if not check_login(text):
|
||||
return send_tmp_message(bot, mes.chat.id, "Не корректный логин")
|
||||
|
||||
data["login"] = text
|
||||
|
||||
@ -184,6 +191,8 @@ def _add_account4(
|
||||
text = mes.text.strip()
|
||||
if text == "/cancel":
|
||||
return send_tmp_message(bot, mes.chat.id, "Успешная отмена")
|
||||
if not check_passwd(text):
|
||||
return send_tmp_message(bot, mes.chat.id, "Не корректный пароль")
|
||||
|
||||
data["passwd"] = text
|
||||
|
||||
|
@ -75,3 +75,23 @@ def accounts_to_json(accounts: list[tuple[str, str, str]]) -> io.StringIO:
|
||||
file = io.StringIO(_accounts_list_to_json(accounts))
|
||||
file.name = "passwords.json"
|
||||
return file
|
||||
|
||||
|
||||
def _base_check(val: str) -> bool:
|
||||
"Returns false if finds new lines or backtick (`)"
|
||||
return not ("\n" in val or "`" in val)
|
||||
|
||||
|
||||
def check_account_name(name: str) -> bool:
|
||||
"Returns true if account name is valid"
|
||||
return _base_check(name)
|
||||
|
||||
|
||||
def check_login(login: str) -> bool:
|
||||
"Returns true if login is valid"
|
||||
return _base_check(login)
|
||||
|
||||
|
||||
def check_passwd(passwd: str) -> bool:
|
||||
"Returns true if password is valid"
|
||||
return _base_check(passwd)
|
||||
|
Reference in New Issue
Block a user