mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-07-14 10:02:25 +03:00
Destroyed Two Factor Authorization (markdown)
parent
adb50a3b0b
commit
e1cf0c680b
|
@ -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!
|
|
Loading…
Reference in New Issue
Block a user