0

Как сделать авторизацию входа в бота с помощью логина и пароля, чтобы каждый раз не вносить user_id новым пользователям?

Импортировать сразу все логины и пароли в базу данных. В базе данных будет таблица USERS еде будут два столбца username (логин), password (пароль)

Щас пользуюсь функцией которая авторизует пользователя по user_id и дает доступ функционалу бота:

сon = sqlite3.connect(settings.DATA_BASE)
with con:
    cur = con.cursor()    
    cur.execute("""SELECT user_id FROM USERS""")
    user_ids = [row[0] for row in cur.fetchall()]

@bot.message_handler(func=lambda message: message.chat.id not in user_ids)
def access_msg(message):
    core.log(message.chat, message.text)
    msg = "ДОСТУП ЗАБОРОЩЕН"
    bot.send_message(message.chat.id, text=msg, parse_mode='HTML')

1 ответ 1

0

В общем принцип такой.

сon = sqlite3.connect(settings.DATA_BASE)
cur = con.cursor()
sql = """SELECT full_name from users WHERE username = ? AND password = ?;"""
cur.execute(sql)
if not cur.fetchone():  # An empty result evaluates to False.
    print("Login failed")
else:
    print("Welcome")

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.