UserFormAuthenticator.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using SteamAuth;
  2. using SteamKit2.Authentication;
  3. using System.Threading.Tasks;
  4. using System.Windows.Forms;
  5. namespace Steam_Desktop_Authenticator
  6. {
  7. internal class UserFormAuthenticator : IAuthenticator
  8. {
  9. private SteamGuardAccount account;
  10. private int deviceCodesGenerated = 0;
  11. public UserFormAuthenticator(SteamGuardAccount account)
  12. {
  13. this.account = account;
  14. }
  15. public Task<bool> AcceptDeviceConfirmationAsync()
  16. {
  17. return Task.FromResult(false);
  18. }
  19. public async Task<string> GetDeviceCodeAsync(bool previousCodeWasIncorrect)
  20. {
  21. // If a code fails wait 30 seconds for a new one to regenerate
  22. if (previousCodeWasIncorrect)
  23. {
  24. // After 2 tries tell the user that there seems to be an issue
  25. if (deviceCodesGenerated > 2)
  26. 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?");
  27. await Task.Delay(30000);
  28. }
  29. string deviceCode;
  30. if (account == null)
  31. {
  32. MessageBox.Show("This account already has an authenticator linked. You must remove that authenticator to add SDA as your authenticator.", "Steam Login", MessageBoxButtons.OK, MessageBoxIcon.Error);
  33. return null;
  34. }
  35. else
  36. {
  37. deviceCode = await account.GenerateSteamGuardCodeAsync();
  38. deviceCodesGenerated++;
  39. }
  40. return deviceCode;
  41. }
  42. public Task<string> GetEmailCodeAsync(string email, bool previousCodeWasIncorrect)
  43. {
  44. string message = "Enter the code sent to your email:";
  45. if (previousCodeWasIncorrect)
  46. {
  47. message = "The code you provided was invalid. Enter the code sent to your email:";
  48. }
  49. InputForm emailForm = new InputForm(message);
  50. emailForm.ShowDialog();
  51. return Task.FromResult(emailForm.txtBox.Text);
  52. }
  53. }
  54. }