forked from KeyAuth/KeyAuth-CPP-Example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
223 lines (190 loc) · 7.75 KB
/
main.cpp
File metadata and controls
223 lines (190 loc) · 7.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#include <Windows.h>
#include "auth.hpp"
#include <string>
#include <thread>
#include "utils.hpp"
#include "skStr.h"
#include <iostream>
std::string tm_to_readable_time(tm ctx);
static std::time_t string_to_timet(std::string timestamp);
static std::tm timet_to_tm(time_t timestamp);
const std::string compilation_date = (std::string)skCrypt(__DATE__);
const std::string compilation_time = (std::string)skCrypt(__TIME__);
void sessionStatus();
using namespace KeyAuth;
// copy and paste from https://keyauth.cc/app/ and replace these string variables
// Please watch tutorial HERE https://www.youtube.com/watch?v=5x4YkTmFH-U
std::string name = skCrypt("name").decrypt(); // App name
std::string ownerid = skCrypt("ownerid").decrypt(); // Account ID
std::string version = skCrypt("1.0").decrypt(); // Application version. Used for automatic downloads see video here https://www.youtube.com/watch?v=kW195PLCBKs
std::string url = skCrypt("https://keyauth.win/api/1.3/").decrypt(); // change if using KeyAuth custom domains feature
std::string path = skCrypt("").decrypt(); // (OPTIONAL) see tutorial here https://www.youtube.com/watch?v=I9rxt821gMk&t=1s
api KeyAuthApp(name, ownerid, version, url, path);
int main()
{
std::string consoleTitle = skCrypt("Loader - Built at: ").decrypt() + compilation_date + " " + compilation_time;
SetConsoleTitleA(consoleTitle.c_str());
std::cout << skCrypt("\n\n Connecting..");
KeyAuthApp.init();
if (!KeyAuthApp.response.success)
{
std::cout << skCrypt("\n Status: ") << KeyAuthApp.response.message;
Sleep(1500);
exit(1);
}
std::string username, password, key, TfaCode; // keep this before the auto-login with saved file.
// because if you don't and the user has 2FA on, then they won't be asked for 2FA code and can't login.
if (std::filesystem::exists("test.json")) //change test.txt to the path of your file :smile:
{
if (!CheckIfJsonKeyExists("test.json", "username"))
{
key = ReadFromJson("test.json", "license");
KeyAuthApp.license(key);
}
else
{
username = ReadFromJson("test.json", "username");
password = ReadFromJson("test.json", "password");
KeyAuthApp.login(username, password);
}
}
else
{
std::cout << skCrypt("\n\n [1] Login\n [2] Register\n [3] Upgrade\n [4] License key only\n\n Choose option: ");
int option;
std::cin >> option;
switch (option)
{
case 1:
std::cout << skCrypt("\n\n Enter username: ");
std::cin >> username;
std::cout << skCrypt("\n Enter password: ");
std::cin >> password;
KeyAuthApp.login(username, password, "");
break;
case 2:
std::cout << skCrypt("\n\n Enter username: ");
std::cin >> username;
std::cout << skCrypt("\n Enter password: ");
std::cin >> password;
std::cout << skCrypt("\n Enter license: ");
std::cin >> key;
KeyAuthApp.regstr(username, password, key);
break;
case 3:
std::cout << skCrypt("\n\n Enter username: ");
std::cin >> username;
std::cout << skCrypt("\n Enter license: ");
std::cin >> key;
KeyAuthApp.upgrade(username, key);
break;
case 4:
std::cout << skCrypt("\n Enter license: ");
std::cin >> key;
KeyAuthApp.license(key, "");
break;
default:
std::cout << skCrypt("\n\n Status: Failure: Invalid Selection");
Sleep(3000);
exit(1);
}
}
if (KeyAuthApp.response.message.empty()) exit(11);
if (!KeyAuthApp.response.success)
{
if (KeyAuthApp.response.message == "2FA code required.") {
if (username.empty() || password.empty()) {
std::cout << skCrypt("\n Your account has 2FA enabled, please enter 6-digit code:");
std::cin >> TfaCode;
KeyAuthApp.license(key, TfaCode);
}
else {
std::cout << skCrypt("\n Your account has 2FA enabled, please enter 6-digit code:");
std::cin >> TfaCode;
KeyAuthApp.login(username, password, TfaCode);
}
if (KeyAuthApp.response.message.empty()) exit(11);
if (!KeyAuthApp.response.success) {
std::cout << skCrypt("\n Status: ") << KeyAuthApp.response.message;
std::remove("test.json");
Sleep(1500);
exit(1);
}
}
else {
std::cout << skCrypt("\n Status: ") << KeyAuthApp.response.message;
std::remove("test.json");
Sleep(1500);
exit(1);
}
}
if (username.empty() || password.empty())
{
WriteToJson("test.json", "license", key, false, "", "");
std::cout << skCrypt("Successfully Created File For Auto Login");
}
else
{
WriteToJson("test.json", "username", username, true, "password", password);
std::cout << skCrypt("Successfully Created File For Auto Login");
}
/*
* Do NOT remove this checkAuthenticated() function.
* It protects you from cracking, it would be NOT be a good idea to remove it
*/
std::thread run(checkAuthenticated, ownerid);
// do NOT remove checkAuthenticated(), it MUST stay for security reasons
std::thread check(sessionStatus); // do NOT remove this function either.
//enable 2FA
// KeyAuthApp.enable2fa(); you will need to ask for the code
//enable 2fa without the need of asking for the code
//KeyAuthApp.enable2fa().handleInput(KeyAuthApp);
//disbale 2FA
// KeyAuthApp.disable2fa();
if (KeyAuthApp.user_data.username.empty()) exit(10);
std::cout << skCrypt("\n User data:");
std::cout << skCrypt("\n Username: ") << KeyAuthApp.user_data.username;
std::cout << skCrypt("\n IP address: ") << KeyAuthApp.user_data.ip;
std::cout << skCrypt("\n Hardware-Id: ") << KeyAuthApp.user_data.hwid;
std::cout << skCrypt("\n Create date: ") << tm_to_readable_time(timet_to_tm(string_to_timet(KeyAuthApp.user_data.createdate)));
std::cout << skCrypt("\n Last login: ") << tm_to_readable_time(timet_to_tm(string_to_timet(KeyAuthApp.user_data.lastlogin)));
std::cout << skCrypt("\n Subscription(s): ");
for (int i = 0; i < KeyAuthApp.user_data.subscriptions.size(); i++) {
auto sub = KeyAuthApp.user_data.subscriptions.at(i);
std::cout << skCrypt("\n name: ") << sub.name;
std::cout << skCrypt(" : expiry: ") << tm_to_readable_time(timet_to_tm(string_to_timet(sub.expiry)));
}
std::cout << skCrypt("\n\n Status: ") << KeyAuthApp.response.message;
std::cout << skCrypt("\n\n Closing in five seconds...");
Sleep(5000);
return 0;
}
void sessionStatus() {
KeyAuthApp.check(true); // do NOT specify true usually, it is slower and will get you blocked from API
if (!KeyAuthApp.response.success) {
exit(0);
}
if (KeyAuthApp.response.isPaid) {
while (true) {
Sleep(20000); // this MUST be included or else you get blocked from API
KeyAuthApp.check();
if (!KeyAuthApp.response.success) {
exit(0);
}
}
}
}
std::string tm_to_readable_time(tm ctx) {
char buffer[80];
strftime(buffer, sizeof(buffer), "%a %m/%d/%y %H:%M:%S %Z", &ctx);
return std::string(buffer);
}
static std::time_t string_to_timet(std::string timestamp) {
auto cv = strtol(timestamp.c_str(), NULL, 10); // long
return (time_t)cv;
}
static std::tm timet_to_tm(time_t timestamp) {
std::tm context;
localtime_s(&context, ×tamp);
return context;
}