-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added a separate password-hash generator executable, auth table popul…
…ation from an auth-file
- Loading branch information
Showing
11 changed files
with
144 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include "auth.hpp" | ||
|
||
std::optional<std::unordered_map<std::string, auth_data>> | ||
open_auth_table_from_file(fs::path file_path) { | ||
std::ifstream file; | ||
file.open(file_path); | ||
if (!file.is_open()) { | ||
return std::nullopt; | ||
} | ||
|
||
std::unordered_map<std::string, auth_data> auth_table; | ||
std::string current_line; | ||
|
||
// parsing line by line with the following format: | ||
// login:permissions:password_hash | ||
while (std::getline(file, current_line)) { | ||
std::size_t first_delimeter = current_line.find(':'); | ||
if (first_delimeter == std::string::npos) { | ||
continue; | ||
} | ||
|
||
std::size_t second_delimeter = current_line.find(':', first_delimeter + 1); | ||
if (second_delimeter == std::string::npos || current_line.size() == second_delimeter) { | ||
continue; | ||
} | ||
|
||
std::string login = current_line.substr(0, first_delimeter); | ||
std::string permissions_str = | ||
current_line.substr( | ||
first_delimeter + 1, | ||
second_delimeter - first_delimeter - 1 | ||
); | ||
unsigned int permissions = 99; | ||
try { | ||
permissions = std::stoi(permissions_str); | ||
} | ||
catch (...) { | ||
continue; | ||
} | ||
if (permissions > 2) { | ||
continue; | ||
} | ||
|
||
std::string password_hash = current_line.substr(second_delimeter + 1); | ||
|
||
auth_table.insert({ | ||
login, | ||
auth_data( | ||
static_cast<AuthorizationType>(permissions), | ||
password_hash | ||
) | ||
}); | ||
} | ||
|
||
file.close(); | ||
|
||
return auth_table; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <bcrypt.h> | ||
#include <iostream> | ||
#include <string> | ||
|
||
int main(int argc, char* argv[]) { | ||
if (argc < 2) { | ||
printf("Usage: %s <password-to-hash>", argv[0]); | ||
return 1; | ||
} | ||
|
||
std::string password(argv[1]); | ||
std::string password_hash = bcrypt::generateHash(password); | ||
|
||
printf("%s", password_hash.c_str()); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters