Merge pull request #3 from noslouch/feat/support-2fa

feat: support two factor auth
This commit is contained in:
Logan Williams
2021-07-20 14:51:17 +02:00
committed by GitHub

View File

@@ -1,10 +1,11 @@
#!/usr/local/bin/python3
from telethon import TelegramClient, events, sync
from telethon import TelegramClient, errors, events, sync
from telethon.tl.types import InputPhoneContact
from telethon import functions, types
from dotenv import load_dotenv
import argparse
import os
from getpass import getpass
load_dotenv()
@@ -57,6 +58,10 @@ if __name__ == '__main__':
client.connect()
if not client.is_user_authorized():
client.send_code_request(PHONE_NUMBER)
client.sign_in(PHONE_NUMBER, input('Enter the code (sent on telegram): '))
try:
client.sign_in(PHONE_NUMBER, input('Enter the code (sent on telegram): '))
except errors.SessionPasswordNeededError:
pw = getpass('Two-Step Verification enabled. Please enter your account password: ')
client.sign_in(password=pw)
user_validator()
print(result)