mirror of
https://github.com/wiz0u/WTelegramClient.git
synced 2025-12-06 06:52:01 +01:00
Retry wrong password/verification_code up to MaxCodePwdAttempts times
This commit is contained in:
parent
4a9652dc7a
commit
6aef50db85
|
|
@ -36,6 +36,8 @@ namespace WTelegram
|
||||||
public Config TLConfig { get; private set; }
|
public Config TLConfig { get; private set; }
|
||||||
/// <summary>Number of automatic reconnections on connection/reactor failure</summary>
|
/// <summary>Number of automatic reconnections on connection/reactor failure</summary>
|
||||||
public int MaxAutoReconnects { get; set; } = 5;
|
public int MaxAutoReconnects { get; set; } = 5;
|
||||||
|
/// <summary>Number of attempts in case of wrong verification_code or password</summary>
|
||||||
|
public int MaxCodePwdAttempts { get; set; } = 3;
|
||||||
/// <summary>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</summary>
|
/// <summary>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</summary>
|
||||||
public int FloodRetryThreshold { get; set; } = 60;
|
public int FloodRetryThreshold { get; set; } = 60;
|
||||||
/// <summary>Number of seconds between each keep-alive ping. Increase this if you have a slow connection or you're debugging your code</summary>
|
/// <summary>Number of seconds between each keep-alive ping. Increase this if you have a slow connection or you're debugging your code</summary>
|
||||||
|
|
@ -955,15 +957,26 @@ namespace WTelegram
|
||||||
}
|
}
|
||||||
authorization = await this.Auth_SignIn(phone_number, sentCode.phone_code_hash, verification_code);
|
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")
|
catch (RpcException e) when (e.Code == 401 && e.Message == "SESSION_PASSWORD_NEEDED")
|
||||||
|
{
|
||||||
|
for (int pwdRetry = 1; authorization == null; pwdRetry++)
|
||||||
|
try
|
||||||
{
|
{
|
||||||
var accountPassword = await this.Account_GetPassword();
|
var accountPassword = await this.Account_GetPassword();
|
||||||
OnUpdate(accountPassword);
|
OnUpdate(accountPassword);
|
||||||
var checkPasswordSRP = await Check2FA(accountPassword, () => ConfigAsync("password"));
|
var checkPasswordSRP = await Check2FA(accountPassword, () => ConfigAsync("password"));
|
||||||
authorization = await this.Auth_CheckPassword(checkPasswordSRP);
|
authorization = await this.Auth_CheckPassword(checkPasswordSRP);
|
||||||
}
|
}
|
||||||
catch (RpcException e) when (e.Code == 400 && e.Message == "PHONE_CODE_INVALID" && retry != 3)
|
catch (RpcException pe) when (pe.Code == 400 && pe.Message == "PASSWORD_HASH_INVALID")
|
||||||
{
|
{
|
||||||
|
Helpers.Log(4, "Wrong password!");
|
||||||
|
if (pwdRetry == MaxCodePwdAttempts) throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
|
|
|
||||||
|
|
@ -1882,7 +1882,7 @@ namespace TL
|
||||||
unsave = unsave,
|
unsave = unsave,
|
||||||
});
|
});
|
||||||
|
|
||||||
/// <summary>Query an inline bot <para>See <a href="https://corefork.telegram.org/method/messages.getInlineBotResults"/></para> <para>Possible <see cref="RpcException"/> codes: -503,400 (<a href="https://corefork.telegram.org/method/messages.getInlineBotResults#possible-errors">details</a>)</para></summary>
|
/// <summary>Query an inline bot <para>See <a href="https://corefork.telegram.org/method/messages.getInlineBotResults"/></para> <para>Possible <see cref="RpcException"/> codes: 400,-503 (<a href="https://corefork.telegram.org/method/messages.getInlineBotResults#possible-errors">details</a>)</para></summary>
|
||||||
/// <param name="bot">The bot to query</param>
|
/// <param name="bot">The bot to query</param>
|
||||||
/// <param name="peer">The currently opened chat</param>
|
/// <param name="peer">The currently opened chat</param>
|
||||||
/// <param name="geo_point">The geolocation, if requested</param>
|
/// <param name="geo_point">The geolocation, if requested</param>
|
||||||
|
|
@ -1993,7 +1993,7 @@ namespace TL
|
||||||
entities = entities,
|
entities = entities,
|
||||||
});
|
});
|
||||||
|
|
||||||
/// <summary>Press an inline callback button and get a callback answer from the bot <para>See <a href="https://corefork.telegram.org/method/messages.getBotCallbackAnswer"/></para> <para>Possible <see cref="RpcException"/> codes: -503,400 (<a href="https://corefork.telegram.org/method/messages.getBotCallbackAnswer#possible-errors">details</a>)</para></summary>
|
/// <summary>Press an inline callback button and get a callback answer from the bot <para>See <a href="https://corefork.telegram.org/method/messages.getBotCallbackAnswer"/></para> <para>Possible <see cref="RpcException"/> codes: 400,-503 (<a href="https://corefork.telegram.org/method/messages.getBotCallbackAnswer#possible-errors">details</a>)</para></summary>
|
||||||
/// <param name="game">Whether this is a "play game" button</param>
|
/// <param name="game">Whether this is a "play game" button</param>
|
||||||
/// <param name="peer">Where was the inline keyboard sent</param>
|
/// <param name="peer">Where was the inline keyboard sent</param>
|
||||||
/// <param name="msg_id">ID of the Message with the inline keyboard</param>
|
/// <param name="msg_id">ID of the Message with the inline keyboard</param>
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@
|
||||||
<PackageId>WTelegramClient</PackageId>
|
<PackageId>WTelegramClient</PackageId>
|
||||||
<Version>0.0.0</Version>
|
<Version>0.0.0</Version>
|
||||||
<Authors>Wizou</Authors>
|
<Authors>Wizou</Authors>
|
||||||
<Description>Telegram Client API library written 100% in C# and .NET Standard | Latest MTProto & API layer version</Description>
|
<Description>Telegram Client API library written 100% in C# and .NET Standard | Latest MTProto & Telegram API layer version</Description>
|
||||||
<Copyright>Copyright © Olivier Marcoux 2021-2022</Copyright>
|
<Copyright>Copyright © Olivier Marcoux 2021-2022</Copyright>
|
||||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||||
<PackageProjectUrl>https://github.com/wiz0u/WTelegramClient</PackageProjectUrl>
|
<PackageProjectUrl>https://github.com/wiz0u/WTelegramClient</PackageProjectUrl>
|
||||||
|
|
@ -46,9 +46,9 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
|
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
|
||||||
<PackageReference Include="IndexRange" Version="1.0.0" />
|
<PackageReference Include="IndexRange" Version="1.0.2" />
|
||||||
<PackageReference Include="System.Memory" Version="4.5.4" />
|
<PackageReference Include="System.Memory" Version="4.5.5" />
|
||||||
<PackageReference Include="System.Text.Json" Version="5.0.2" />
|
<PackageReference Include="System.Text.Json" Version="6.0.4" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue