@@ -39,42 +39,28 @@ int main()
3939 exit (1 );
4040 }
4141
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+
4245 if (std::filesystem::exists (" test.json" )) // change test.txt to the path of your file :smile:
4346 {
4447 if (!CheckIfJsonKeyExists (" test.json" , " username" ))
4548 {
46- std::string key = ReadFromJson (" test.json" , " license" );
49+ key = ReadFromJson (" test.json" , " license" );
4750 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 " );
5651 }
5752 else
5853 {
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" );
6156 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 " );
7057 }
7158 }
7259 else
7360 {
7461 std::cout << skCrypt (" \n\n [1] Login\n [2] Register\n [3] Upgrade\n [4] License key only\n\n Choose option: " );
7562
7663 int option;
77- std::string username, password, key, TfaCode;
7864
7965 std::cin >> option;
8066 switch (option)
@@ -84,9 +70,7 @@ int main()
8470 std::cin >> username;
8571 std::cout << skCrypt (" \n Enter password: " );
8672 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, " " );
9074 break ;
9175 case 2 :
9276 std::cout << skCrypt (" \n\n Enter username: " );
@@ -107,34 +91,55 @@ int main()
10791 case 4 :
10892 std::cout << skCrypt (" \n Enter license: " );
10993 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, " " );
11395 break ;
11496 default :
11597 std::cout << skCrypt (" \n\n Status: Failure: Invalid Selection" );
11698 Sleep (3000 );
11799 exit (1 );
118100 }
101+ }
119102
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 {
123127 std::cout << skCrypt (" \n Status: " ) << KeyAuthApp.response .message ;
128+ std::remove (" test.json" );
124129 Sleep (1500 );
125130 exit (1 );
126131 }
132+ }
127133
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" );
138143 }
139144
140145 /*
0 commit comments