Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support two factor auth #3

Merged
merged 1 commit into from
Jul 20, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions telegram-phone-validation.py
Original file line number Diff line number Diff line change
@@ -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()

Expand Down Expand Up @@ -57,6 +58,10 @@ def user_validator():
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)