From e1cf0c680bcba5e1524537ad4ebfc3339a3279b6 Mon Sep 17 00:00:00 2001 From: Lonami Date: Mon, 25 Jun 2018 09:33:16 +0200 Subject: [PATCH] Destroyed Two Factor Authorization (markdown) --- Two-Factor-Authorization.md | 43 ------------------------------------- 1 file changed, 43 deletions(-) delete mode 100644 Two-Factor-Authorization.md diff --git a/Two-Factor-Authorization.md b/Two-Factor-Authorization.md deleted file mode 100644 index e7f779e..0000000 --- a/Two-Factor-Authorization.md +++ /dev/null @@ -1,43 +0,0 @@ -If you have Two Factor Authorization (from now on, 2FA) enabled on your account, calling `.sign_in` will raise a `SessionPasswordNeededError`. When this happens, just `.sign_in()` again with a `password=`: - -```python -import getpass -from telethon.errors import SessionPasswordNeededError - -client.sign_in(phone) -try: - client.sign_in(code=input('Enter code: ')) -except SessionPasswordNeededError: - client.sign_in(password=getpass.getpass()) -``` - -## Enabling 2FA - -If you don't have 2FA enabled, but you would like to do so through Telethon, take as example the following code snippet: - -```python -import os -from hashlib import sha256 -from telethon.tl.functions import account -from telethon.tl.types.account import PasswordInputSettings - -new_salt = client(account.GetPasswordRequest()).new_salt -salt = new_salt + os.urandom(8) # new random salt - -pw = 'secret'.encode('utf-8') # type your new password here -hint = 'hint' - -pw_salted = salt + pw + salt -pw_hash = sha256(pw_salted).digest() - -result = client(account.UpdatePasswordSettingsRequest( - current_password_hash=salt, - new_settings=PasswordInputSettings( - new_salt=salt, - new_password_hash=pw_hash, - hint=hint - ) -)) -``` - -Thanks to [issue 259](https://github.com/LonamiWebs/Telethon/issues/259) for the tip! \ No newline at end of file