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