LonamiWebs / Telethon

Pure Python 3 MTProto API Telegram client library, for bots too!
https://docs.telethon.dev
MIT License
9.9k stars 1.4k forks source link

Login with another phone, code always expired #97

Closed farodrig closed 7 years ago

farodrig commented 7 years ago

Hi, when I tried to login with a phone different than the one I used in the telegram API registration, the client always send me a code expired message when I provide the code for the login.

I don't know if what I'm trying to do is not supported or what. This happen using the interactive telegram client. (I'm trying to login with a different number, providing the correct login code).

I hope someone could help me.

(I am not a native speaker, sorry for my english)

Lonami commented 7 years ago

Are you sure you're using the code sent to that phone and not to your main phone?

farodrig commented 7 years ago

Yes, I'm sure.

Using my app_ID and my app_hash provided by Telegram, I put the phone number of a friend sat next to me, he received the code in his phone and I put it in the client and responded me a code expired error.

I'm supposed to be able to do this, right?

Lonami commented 7 years ago

I'm supposed to be able to do this, right?

Yes, it's really strange it doesn't work with a different phone number. Do you have other phone numbers to test this with? I presume that the computer you're working with has the right time zone and such? Sorry https://core.telegram.org/api/errors doesn't give much more information about PHONE_CODE_EXPIRED.

Both people here and here mentioned it's a DC issue, but those should be handled gracefully already. Try changing the default one under session.py in the Session class? Maybe with the IP that api.telegram.org shows?

FrayxRulez commented 7 years ago

@farodrig are you sending the code via Telegram to another account before using it?

farodrig commented 7 years ago

yes!! It's that??

FrayxRulez commented 7 years ago

Yep, if you send an auth code via Telegram it expires automatically

Lonami commented 7 years ago

Thank you @FrayxRulez :)

LeeHJones commented 6 years ago

Confirmed on this, btw. As soon as I had a colleague send me the login code via WhatsApp, everything worked perfectly. Huge props to @FrayxRulez .

Lonami commented 6 years ago

I had completely forgotten about this issue and it was discussed again recently on another Telegram API-related group. Closing #516.

SmartManoj commented 5 years ago

@FrayxRulez How the code expires when sending through telegram?

Lonami commented 5 years ago

It's a server-side check to prevent people from "accidentally" telling a possible attacker the code.

SmartManoj commented 5 years ago

@Lonami Even in Secret Chats?Are only the particular users message validated ?

alex2304 commented 5 years ago

That feeling when you don't send code to anyone, and it is always expired... =/

gespispace commented 5 years ago

That feeling when you don't send code to anyone, and it is always expired... =/

Can you solve the problem?

SmartManoj commented 5 years ago

Yep, if you send an auth code via Telegram it expires automatically

Append zero with code to obscure it

shakibm83 commented 3 years ago

That feeling when you don't send code to anyone, and it is always expired... =/

Can you solve the problem?

I added a letter before the code. for example if code is 12345 I send s12345 and that's work

redradist commented 2 years ago

Guys, I have the same issue !! How to fix it ?

I have a Telegram Bot that also use Telethon client for sing_in ? When I provide a code to it I see that code is always expired !!

Guys, do you have solution ?

ggnetoo commented 1 year ago

Guys, I have the same issue !! How to fix it ?

I have a Telegram Bot that also use Telethon client for sing_in ? When I provide a code to it I see that code is always expired !!

Guys, do you have solution ?

Me too. Got a solution?

Lau1Re commented 1 year ago

When you logging in, you should write your code like a this one: "241 26", in other words - with spaces. But if you trying to log in with your own account and write code like 24126 (without spaces) - your code will be always expired

aienabled commented 1 year ago

I was struggling for half a year with this particular error (PHONE_CODE_EXPIRED) when trying to log in with my own account (other accounts could log in without any issues). The solution? As @shakibm83 suggested above, I've added a single letter before the phone code number. And it works now. Just wow. Had to use another account all that time... Thank you, @shakibm83!

Regards!

paweldzia commented 10 months ago

Maybe I misunderstand something completely - still having the same issue.

  1. I request the code via client.send_code_request(phone_number)
  2. I get the code automatically via Telegram (from the user "Telegram")
  3. I type in the code in my app within 10-15 seconds after receiving it
  4. Error: PhoneCodeExpiredError

I don't obfuscate the code in any way so far, but also I wouldn't even have the possibility as the code is being sent upon client.send_code_request automatically, right?

I have both apps, the Telegram app and my custom app, on the same phone, so when I request the code in my custom app, I see the delivered code in the Telegram app notification (because of the new message from Telegram) and type it directly into my custom app, but then get the error "expired".

It applies both, to my real number as well as to the test numbers provided by Telegram (eg +99966XYYYY, depending on the test DC appointed in the API access data).

Interestingly, I had this issue in the beginning of development, then it somehow just worked and now it again doesn't work anymore.

Edit: Just noticed that it's a closed issue, will open a new one then.

aienabled commented 2 months ago

I've got the same issue once again. Turns out it's very simple...the reason and the solution are explained here https://stackoverflow.com/questions/78591390/phone-code-expired-caused-by-auth-signin-error-during-authorization-using-node

Reason: Telegram security service watches your messages so whenever you try to send your one-time code (received via Telegram) to someone else via Telegram (even if you send to your own bot) the code is made invalid immediately (and reported as "expired", with an odd message from Telegram to your account telling you that your login attempt was unsuccessful and nobody gained access to your account). A probable explanation is that it's done to protect your account from hackers.

Solution: Never send your one-time code as-is to your bot. Obfuscate the code when typing in a message to your bot (e.g. by putting letters between numbers 12345 -> 1a2a3a4a5) and then deobfuscate by your bot. This way Telegram security service will not trigger and your one-time code will not "expire".

Regards!