Merge pull request #1286 from LTe/config-parse-boolean-to-string
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
// standard includes
|
// standard includes
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
// lib includes
|
// lib includes
|
||||||
@@ -68,11 +69,12 @@ namespace http {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int save_user_creds(const std::string &file, const std::string &username, const std::string &password, bool run_our_mouth) {
|
int save_user_creds(const std::string &file, const std::string &username, const std::string &password, bool run_our_mouth) {
|
||||||
pt::ptree outputTree;
|
nlohmann::json outputTree;
|
||||||
|
|
||||||
if (fs::exists(file)) {
|
if (fs::exists(file)) {
|
||||||
try {
|
try {
|
||||||
pt::read_json(file, outputTree);
|
std::ifstream in(file);
|
||||||
|
in >> outputTree;
|
||||||
} catch (std::exception &e) {
|
} catch (std::exception &e) {
|
||||||
BOOST_LOG(error) << "Couldn't read user credentials: "sv << e.what();
|
BOOST_LOG(error) << "Couldn't read user credentials: "sv << e.what();
|
||||||
return -1;
|
return -1;
|
||||||
@@ -80,11 +82,12 @@ namespace http {
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto salt = crypto::rand_alphabet(16);
|
auto salt = crypto::rand_alphabet(16);
|
||||||
outputTree.put("username", username);
|
outputTree["username"] = username;
|
||||||
outputTree.put("salt", salt);
|
outputTree["salt"] = salt;
|
||||||
outputTree.put("password", util::hex(crypto::hash(password + salt)).to_string());
|
outputTree["password"] = util::hex(crypto::hash(password + salt)).to_string();
|
||||||
try {
|
try {
|
||||||
pt::write_json(file, outputTree);
|
std::ofstream out(file);
|
||||||
|
out << outputTree.dump(4); // Pretty-print with an indent of 4 spaces.
|
||||||
} catch (std::exception &e) {
|
} catch (std::exception &e) {
|
||||||
BOOST_LOG(error) << "error writing to the credentials file, perhaps try this again as an administrator? Details: "sv << e.what();
|
BOOST_LOG(error) << "error writing to the credentials file, perhaps try this again as an administrator? Details: "sv << e.what();
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
Reference in New Issue
Block a user