Skip to content

Commit

Permalink
Handle issue where steam fails to login due to incorrect device codes
Browse files Browse the repository at this point in the history
  • Loading branch information
Jessecar96 committed Jun 29, 2023
1 parent 0253c76 commit bf9896a
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions Steam Desktop Authenticator/UserFormAuthenticator.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using SteamAuth;
using SteamKit2.Authentication;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Steam_Desktop_Authenticator
{
internal class UserFormAuthenticator : IAuthenticator
{
private SteamGuardAccount account;
private int deviceCodesGenerated = 0;

public UserFormAuthenticator(SteamGuardAccount account)
{
Expand All @@ -20,12 +22,31 @@ public Task<bool> AcceptDeviceConfirmationAsync()

public async Task<string> GetDeviceCodeAsync(bool previousCodeWasIncorrect)
{
return await account.GenerateSteamGuardCodeAsync();
// If a code fails wait 30 seconds for a new one to regenerate
if (previousCodeWasIncorrect)
{
// After 2 tries tell the user that there seems to be an issue
if (deviceCodesGenerated > 2)
MessageBox.Show("There seems to be an issue logging into your account with these two factor codes. Are you sure SDA is still your authenticator?");

await Task.Delay(30000);
}

string deviceCode = await account.GenerateSteamGuardCodeAsync();
deviceCodesGenerated++;

return deviceCode;
}

public Task<string> GetEmailCodeAsync(string email, bool previousCodeWasIncorrect)
{
InputForm emailForm = new InputForm("Enter the code sent to your email:");
string message = "Enter the code sent to your email:";
if (previousCodeWasIncorrect)
{
message = "The code you provided was invalid. Enter the code sent to your email:";
}

InputForm emailForm = new InputForm(message);
emailForm.ShowDialog();
return Task.FromResult(emailForm.txtBox.Text);
}
Expand Down

0 comments on commit bf9896a

Please sign in to comment.