From 6aef50db85677ef706e9ea6c6a30d50a95d3992d Mon Sep 17 00:00:00 2001
From: Wizou <11647984+wiz0u@users.noreply.github.com>
Date: Tue, 31 May 2022 14:28:37 +0200
Subject: [PATCH] Retry wrong password/verification_code up to
MaxCodePwdAttempts times
---
src/Client.cs | 27 ++++++++++++++++++++-------
src/TL.SchemaFuncs.cs | 4 ++--
src/WTelegramClient.csproj | 8 ++++----
3 files changed, 26 insertions(+), 13 deletions(-)
diff --git a/src/Client.cs b/src/Client.cs
index 711115a..f5cf015 100644
--- a/src/Client.cs
+++ b/src/Client.cs
@@ -36,6 +36,8 @@ namespace WTelegram
public Config TLConfig { get; private set; }
/// Number of automatic reconnections on connection/reactor failure
public int MaxAutoReconnects { get; set; } = 5;
+ /// Number of attempts in case of wrong verification_code or password
+ public int MaxCodePwdAttempts { get; set; } = 3;
/// Number of seconds under which an error 420 FLOOD_WAIT_X will not be raised and your request will instead be auto-retried after the delay
public int FloodRetryThreshold { get; set; } = 60;
/// Number of seconds between each keep-alive ping. Increase this if you have a slow connection or you're debugging your code
@@ -955,15 +957,26 @@ namespace WTelegram
}
authorization = await this.Auth_SignIn(phone_number, sentCode.phone_code_hash, verification_code);
}
+ catch (RpcException e) when (e.Code == 400 && e.Message == "PHONE_CODE_INVALID")
+ {
+ Helpers.Log(4, "Wrong verification code!");
+ if (retry == MaxCodePwdAttempts) throw;
+ }
catch (RpcException e) when (e.Code == 401 && e.Message == "SESSION_PASSWORD_NEEDED")
{
- var accountPassword = await this.Account_GetPassword();
- OnUpdate(accountPassword);
- var checkPasswordSRP = await Check2FA(accountPassword, () => ConfigAsync("password"));
- authorization = await this.Auth_CheckPassword(checkPasswordSRP);
- }
- catch (RpcException e) when (e.Code == 400 && e.Message == "PHONE_CODE_INVALID" && retry != 3)
- {
+ for (int pwdRetry = 1; authorization == null; pwdRetry++)
+ try
+ {
+ var accountPassword = await this.Account_GetPassword();
+ OnUpdate(accountPassword);
+ var checkPasswordSRP = await Check2FA(accountPassword, () => ConfigAsync("password"));
+ authorization = await this.Auth_CheckPassword(checkPasswordSRP);
+ }
+ catch (RpcException pe) when (pe.Code == 400 && pe.Message == "PASSWORD_HASH_INVALID")
+ {
+ Helpers.Log(4, "Wrong password!");
+ if (pwdRetry == MaxCodePwdAttempts) throw;
+ }
}
}
catch
diff --git a/src/TL.SchemaFuncs.cs b/src/TL.SchemaFuncs.cs
index 912553e..2883d6e 100644
--- a/src/TL.SchemaFuncs.cs
+++ b/src/TL.SchemaFuncs.cs
@@ -1882,7 +1882,7 @@ namespace TL
unsave = unsave,
});
- /// Query an inline bot See Possible codes: -503,400 (details)
+ /// Query an inline bot See Possible codes: 400,-503 (details)
/// The bot to query
/// The currently opened chat
/// The geolocation, if requested
@@ -1993,7 +1993,7 @@ namespace TL
entities = entities,
});
- /// Press an inline callback button and get a callback answer from the bot See Possible codes: -503,400 (details)
+ /// Press an inline callback button and get a callback answer from the bot See Possible codes: 400,-503 (details)
/// Whether this is a "play game" button
/// Where was the inline keyboard sent
/// ID of the Message with the inline keyboard
diff --git a/src/WTelegramClient.csproj b/src/WTelegramClient.csproj
index 493252f..50b34fe 100644
--- a/src/WTelegramClient.csproj
+++ b/src/WTelegramClient.csproj
@@ -13,7 +13,7 @@
WTelegramClient
0.0.0
Wizou
- Telegram Client API library written 100% in C# and .NET Standard | Latest MTProto & API layer version
+ Telegram Client API library written 100% in C# and .NET Standard | Latest MTProto & Telegram API layer version
Copyright © Olivier Marcoux 2021-2022
MIT
https://github.com/wiz0u/WTelegramClient
@@ -46,9 +46,9 @@
-
-
-
+
+
+