@@ -1238,6 +1238,37 @@ void KeyAuth::api::forgot(std::string username, std::string email)
12381238 load_response_data (json);
12391239}
12401240
1241+ void KeyAuth::api::logout () {
1242+ checkInit ();
1243+
1244+ auto data =
1245+ XorStr (" type=logout" ) +
1246+ XorStr (" &sessionid=" ) + sessionid +
1247+ XorStr (" &name=" ) + name +
1248+ XorStr (" &ownerid=" ) + ownerid;
1249+ auto response = req (data, url);
1250+ auto json = response_decoder.parse (response);
1251+ if (json[(XorStr (" success" ))]) {
1252+
1253+ // clear all old user data from program
1254+ user_data.createdate .clear ();
1255+ user_data.ip .clear ();
1256+ user_data.hwid .clear ();
1257+ user_data.lastlogin .clear ();
1258+ user_data.username .clear ();
1259+ user_data.subscriptions .clear ();
1260+
1261+ // clear sessionid
1262+ sessionid.clear ();
1263+
1264+ // clear enckey
1265+ enckey.clear ();
1266+
1267+ }
1268+
1269+ load_response_data (json);
1270+ }
1271+
12411272// credits https://stackoverflow.com/a/3790661
12421273static std::string hexDecode (const std::string& hex)
12431274{
@@ -1466,8 +1497,61 @@ std::string getPath() {
14661497 }
14671498}
14681499
1500+ void RedactField (nlohmann::json& jsonObject, const std::string& fieldName)
1501+ {
1502+
1503+ if (jsonObject.contains (fieldName)) {
1504+ jsonObject[fieldName] = " REDACTED" ;
1505+ }
1506+ }
1507+
14691508void debugInfo (std::string data, std::string url, std::string response) {
14701509
1510+ // turn response into json
1511+ nlohmann::json responses = nlohmann::json::parse (response);
1512+ RedactField (responses, " sessionid" );
1513+ RedactField (responses, " ownerid" );
1514+ RedactField (responses, " app" );
1515+ RedactField (responses, " name" );
1516+ RedactField (responses, " contents" );
1517+ RedactField (responses, " key" );
1518+ RedactField (responses, " username" );
1519+ RedactField (responses, " password" );
1520+ RedactField (responses, " secret" );
1521+ RedactField (responses, " version" );
1522+ RedactField (responses, " fileid" );
1523+ RedactField (responses, " webhooks" );
1524+ std::string redacted_response = responses.dump ();
1525+
1526+ // turn data into json
1527+ std::replace (data.begin (), data.end (), ' &' , ' ' );
1528+
1529+ nlohmann::json datas;
1530+
1531+ std::istringstream iss (data);
1532+ std::vector<std::string> results ((std::istream_iterator<std::string>(iss)),
1533+ std::istream_iterator<std::string>());
1534+
1535+ for (auto const & value : results) {
1536+ datas[value.substr (0 , value.find (' =' ))] = value.substr (value.find (' =' ) + 1 );
1537+ }
1538+
1539+ RedactField (datas, " sessionid" );
1540+ RedactField (datas, " ownerid" );
1541+ RedactField (datas, " app" );
1542+ RedactField (datas, " name" );
1543+ RedactField (datas, " key" );
1544+ RedactField (datas, " username" );
1545+ RedactField (datas, " password" );
1546+ RedactField (datas, " contents" );
1547+ RedactField (datas, " secret" );
1548+ RedactField (datas, " version" );
1549+ RedactField (datas, " fileid" );
1550+ RedactField (datas, " webhooks" );
1551+
1552+ std::string redacted_data = datas.dump ();
1553+
1554+
14711555 // gets the path
14721556 std::string path = getPath ();
14731557
@@ -1485,7 +1569,7 @@ void debugInfo(std::string data, std::string url, std::string response) {
14851569 // /////////////////////
14861570
14871571 // creates variables for the paths needed :smile:
1488- std::string KeyAuthPath = path + " \\ KeyAuth" ;
1572+ std::string KeyAuthPath = path + " \\ KeyAuth" ;
14891573 std::string logPath = KeyAuthPath + " \\ Debug\\ " + filenameOnly.substr (0 , filenameOnly.size () - 4 );
14901574
14911575 // basically loops until we have all the paths
@@ -1530,7 +1614,7 @@ void debugInfo(std::string data, std::string url, std::string response) {
15301614
15311615 std::string currentTimeString = std::to_string (hours) + " :" + formattedMinutes + " " + period;
15321616
1533- std::string contents = " \n\n @ " + currentTimeString + " \n Data sent : " + data + " \n Response : " + response + " Sent to: " + url;
1617+ std::string contents = " \n\n @ " + currentTimeString + " \n Data sent : " + redacted_data + " \n Response : " + redacted_response + " Sent to: " + url;
15341618
15351619 logfile << contents;
15361620
0 commit comments