| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- 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)
- {
- this.account = account;
- }
- public Task<bool> AcceptDeviceConfirmationAsync()
- {
- return Task.FromResult(false);
- }
- public async Task<string> GetDeviceCodeAsync(bool previousCodeWasIncorrect)
- {
- // 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;
- if (account == null)
- {
- 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);
- return null;
- }
- else
- {
- deviceCode = await account.GenerateSteamGuardCodeAsync();
- deviceCodesGenerated++;
- }
- return deviceCode;
- }
- public Task<string> GetEmailCodeAsync(string email, bool previousCodeWasIncorrect)
- {
- 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);
- }
- }
- }
|