-
-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathmain.cpp
More file actions
162 lines (141 loc) · 5.66 KB
/
Copy pathmain.cpp
File metadata and controls
162 lines (141 loc) · 5.66 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
#include <Windows.h>
#include <string>
#include <auth.hpp>
#include "utils.hpp"
#include "skStr.h"
#include <limits> // input validation helpers. -nigel
#include <chrono> // date math for expiry display. -nigel
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);
static std::string remaining_until(std::string timestamp); // human readable expiry countdown. -nigel
const std::string compilation_date = (std::string)skCrypt(__DATE__);
const std::string compilation_time = (std::string)skCrypt(__TIME__);
using namespace KeyAuth;
std::string name = skCrypt("name").decrypt();
std::string ownerid = skCrypt("ownerid").decrypt();
std::string secret = skCrypt("secret").decrypt();
std::string version = skCrypt("1.0").decrypt();
std::string url = skCrypt("https://keyauth.win/api/1.2/").decrypt(); // change if you're self-hosting
std::string path = skCrypt("").decrypt(); //optional, set a path if you're using the token validation setting
api KeyAuthApp(name, ownerid, secret, version, url, path);
int main()
{
// Freeing memory to prevent memory leak or memory scraping
name.clear(); ownerid.clear(); secret.clear(); version.clear(); url.clear();
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::cout << skCrypt("\n\n [1] Login\n [2] Register\n [3] Upgrade\n [4] License key only\n\n Choose option: ");
int option;
std::string username;
std::string password;
std::string key;
std::cin >> option;
if (std::cin.fail())
{
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cout << skCrypt("\n\n Status: Failure: Invalid Selection"); // bad input path. -nigel
Sleep(3000);
exit(1);
}
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.success)
{
std::cout << skCrypt("\n Status: ") << KeyAuthApp.response.message;
Sleep(1500);
exit(1);
}
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(" (") << remaining_until(sub.expiry) << skCrypt(")"); // show time remaining. -nigel
}
std::cout << skCrypt("\n\n Closing in five seconds...");
Sleep(5000);
return 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) {
char* end = nullptr;
auto cv = strtol(timestamp.c_str(), &end, 10);
if (end == timestamp.c_str())
return 0; // invalid timestamp returns epoch. -nigel
return static_cast<time_t>(cv);
}
static std::tm timet_to_tm(time_t timestamp) {
std::tm context;
localtime_s(&context, ×tamp);
return context;
}
static std::string remaining_until(std::string timestamp) {
const auto expiry = string_to_timet(timestamp);
const auto now = std::time(nullptr);
if (expiry <= now)
return "expired"; // already expired. -nigel
auto diff = std::chrono::seconds(expiry - now);
auto days = std::chrono::duration_cast<std::chrono::hours>(diff).count() / 24;
auto weeks = days / 7;
auto months = days / 30;
auto years = days / 365;
std::string out;
if (years > 0) out += std::to_string(years) + "y ";
if (months > 0) out += std::to_string(months % 12) + "mo ";
if (weeks > 0) out += std::to_string(weeks % 4) + "w ";
out += std::to_string(days % 7) + "d";
return out;
}