@@ -39,42 +39,28 @@ int main()
39
39
exit (1 );
40
40
}
41
41
42
+ std::string username, password, key, TfaCode; // keep this before the auto-login with saved file.
43
+ // because if you don't and the user has 2FA on, then they won't be asked for 2FA code and can't login.
44
+
42
45
if (std::filesystem::exists (" test.json" )) // change test.txt to the path of your file :smile:
43
46
{
44
47
if (!CheckIfJsonKeyExists (" test.json" , " username" ))
45
48
{
46
- std::string key = ReadFromJson (" test.json" , " license" );
49
+ key = ReadFromJson (" test.json" , " license" );
47
50
KeyAuthApp.license (key);
48
- if (!KeyAuthApp.response .success )
49
- {
50
- std::remove (" test.json" );
51
- std::cout << skCrypt (" \n Status: " ) << KeyAuthApp.response .message ;
52
- Sleep (1500 );
53
- exit (1 );
54
- }
55
- std::cout << skCrypt (" \n\n Successfully Automatically Logged In\n " );
56
51
}
57
52
else
58
53
{
59
- std::string username = ReadFromJson (" test.json" , " username" );
60
- std::string password = ReadFromJson (" test.json" , " password" );
54
+ username = ReadFromJson (" test.json" , " username" );
55
+ password = ReadFromJson (" test.json" , " password" );
61
56
KeyAuthApp.login (username, password);
62
- if (!KeyAuthApp.response .success )
63
- {
64
- std::remove (" test.json" );
65
- std::cout << skCrypt (" \n Status: " ) << KeyAuthApp.response .message ;
66
- Sleep (1500 );
67
- exit (1 );
68
- }
69
- std::cout << skCrypt (" \n\n Successfully Automatically Logged In\n " );
70
57
}
71
58
}
72
59
else
73
60
{
74
61
std::cout << skCrypt (" \n\n [1] Login\n [2] Register\n [3] Upgrade\n [4] License key only\n\n Choose option: " );
75
62
76
63
int option;
77
- std::string username, password, key, TfaCode;
78
64
79
65
std::cin >> option;
80
66
switch (option)
@@ -84,9 +70,7 @@ int main()
84
70
std::cin >> username;
85
71
std::cout << skCrypt (" \n Enter password: " );
86
72
std::cin >> password;
87
- std::cout << skCrypt (" \n Enter 2fa code if applicable: " );
88
- std::cin >> TfaCode;
89
- KeyAuthApp.login (username, password, TfaCode);
73
+ KeyAuthApp.login (username, password, " " );
90
74
break ;
91
75
case 2 :
92
76
std::cout << skCrypt (" \n\n Enter username: " );
@@ -107,34 +91,55 @@ int main()
107
91
case 4 :
108
92
std::cout << skCrypt (" \n Enter license: " );
109
93
std::cin >> key;
110
- std::cout << skCrypt (" \n Enter 2fa code if applicable: " );
111
- std::cin >> TfaCode;
112
- KeyAuthApp.license (key, TfaCode);
94
+ KeyAuthApp.license (key, " " );
113
95
break ;
114
96
default :
115
97
std::cout << skCrypt (" \n\n Status: Failure: Invalid Selection" );
116
98
Sleep (3000 );
117
99
exit (1 );
118
100
}
101
+ }
119
102
120
- if (KeyAuthApp.response .message .empty ()) exit (11 );
121
- if (!KeyAuthApp.response .success )
122
- {
103
+ if (KeyAuthApp.response .message .empty ()) exit (11 );
104
+ if (!KeyAuthApp.response .success )
105
+ {
106
+ if (KeyAuthApp.response .message == " 2FA code required." ) {
107
+ if (username.empty () || password.empty ()) {
108
+ std::cout << skCrypt (" \n Your account has 2FA enabled, please enter 6-digit code:" );
109
+ std::cin >> TfaCode;
110
+ KeyAuthApp.license (key, TfaCode);
111
+ }
112
+ else {
113
+ std::cout << skCrypt (" \n Your account has 2FA enabled, please enter 6-digit code:" );
114
+ std::cin >> TfaCode;
115
+ KeyAuthApp.login (username, password, TfaCode);
116
+ }
117
+
118
+ if (KeyAuthApp.response .message .empty ()) exit (11 );
119
+ if (!KeyAuthApp.response .success ) {
120
+ std::cout << skCrypt (" \n Status: " ) << KeyAuthApp.response .message ;
121
+ std::remove (" test.json" );
122
+ Sleep (1500 );
123
+ exit (1 );
124
+ }
125
+ }
126
+ else {
123
127
std::cout << skCrypt (" \n Status: " ) << KeyAuthApp.response .message ;
128
+ std::remove (" test.json" );
124
129
Sleep (1500 );
125
130
exit (1 );
126
131
}
132
+ }
127
133
128
- if (username.empty () || password.empty ())
129
- {
130
- WriteToJson (" test.json" , " license" , key, false , " " , " " );
131
- std::cout << skCrypt (" Successfully Created File For Auto Login" );
132
- }
133
- else
134
- {
135
- WriteToJson (" test.json" , " username" , username, true , " password" , password);
136
- std::cout << skCrypt (" Successfully Created File For Auto Login" );
137
- }
134
+ if (username.empty () || password.empty ())
135
+ {
136
+ WriteToJson (" test.json" , " license" , key, false , " " , " " );
137
+ std::cout << skCrypt (" Successfully Created File For Auto Login" );
138
+ }
139
+ else
140
+ {
141
+ WriteToJson (" test.json" , " username" , username, true , " password" , password);
142
+ std::cout << skCrypt (" Successfully Created File For Auto Login" );
138
143
}
139
144
140
145
/*
0 commit comments