From d0d30b73b981c123f8fe9bce232b28091023dc16 Mon Sep 17 00:00:00 2001
From: PI <74706004+pi-314159@users.noreply.github.com>
Date: Mon, 10 Jun 2024 20:51:37 -0500
Subject: [PATCH] Fix code formatting
---
README.md | 22 +++---
VisualStudio/Authenticator.vcxproj | 1 +
src/Authenticator.cpp | 5 +-
src/actions/add.cpp | 107 +++++++++++++++--------------
src/actions/generatetotp.cpp | 4 +-
src/include/actions/add.h | 2 +-
src/include/actions/generatetotp.h | 2 +-
7 files changed, 72 insertions(+), 71 deletions(-)
diff --git a/README.md b/README.md
index 06e236b..f2220e1 100644
--- a/README.md
+++ b/README.md
@@ -2,25 +2,25 @@ This is a TOTP (Time-Based One-Time Password) authenticator that adheres to [RFC
## Build
-Before building, ensure that you have OpenSSL library 3.0 or higher installed and that your compiler supports C++20 standards. By default, the executable is located in the `build` folder.
+Before building, ensure that you have OpenSSL library 3.0 or higher installed and that your compiler supports C++20. By default, the executable is located in the `build` folder.
### Windows
If you're on Windows, you can install OpenSSL using vcpkg. Follow these steps:
1. Install OpenSSL using vcpkg:
- ```bat
- vcpkg.exe install openssl:x64-windows
- ```
- or
- ```bat
- vcpkg.exe install openssl
- ```
+ ```bat
+ vcpkg.exe install openssl:x64-windows
+ ```
+ or
+ ```bat
+ vcpkg.exe install openssl
+ ```
2. Integrate vcpkg with Visual Studio:
- ```bat
- vcpkg integrate install
- ```
+ ```bat
+ vcpkg.exe integrate install
+ ```
3. Build the Visual Studio solution located in the `VisualStudio` folder.
diff --git a/VisualStudio/Authenticator.vcxproj b/VisualStudio/Authenticator.vcxproj
index 9f93b6f..859251a 100644
--- a/VisualStudio/Authenticator.vcxproj
+++ b/VisualStudio/Authenticator.vcxproj
@@ -133,6 +133,7 @@
true
stdc17
stdcpp20
+ Full
Console
diff --git a/src/Authenticator.cpp b/src/Authenticator.cpp
index 0ea3dc8..f2f3b36 100644
--- a/src/Authenticator.cpp
+++ b/src/Authenticator.cpp
@@ -18,11 +18,10 @@
int main(int argc, char* argv[]) {
std::cout << "=========================== PI Authenticator ===========================\n"
- "= Last Updated: 2024-06-05 =\n"
+ "= Last Updated: 2024-06-10 =\n"
"= License: MIT =\n"
"= GitHub Repository: github.com/pi-314159/Authenticator =\n"
- "========================================================================\n\n"
- "Note: Sometimes you may need to hit Enter TWICE after input to continue.\n"<< std::endl;
+ "========================================================================\n\n" << std::endl;
std::string action = "l";
std::vector tOTPObjects;
diff --git a/src/actions/add.cpp b/src/actions/add.cpp
index a8e7a49..99ebd33 100644
--- a/src/actions/add.cpp
+++ b/src/actions/add.cpp
@@ -9,57 +9,58 @@
#include
namespace ACTIONS {
- void Add(std::vector& tOTPObjects) {
- auto str = std::make_unique_for_overwrite();
- std::string inputBuffer, tag, secret;
- char alg = '1';
- unsigned int period;
- unsigned short digits;
- while (inputBuffer.empty()) {
- str->Input(inputBuffer, "Please enter the issuer (e.g., GitHub), then hit Enter TWICE to proceed:", true);
- str->FormatInput(inputBuffer, inputBuffer);
- }
- tag = inputBuffer + "::";
- inputBuffer = "";
- while (inputBuffer.empty()) {
- str->Input(inputBuffer, "Please enter the account (e.g., user@example.com), \nthen hit Enter TWICE to proceed:", true);
- str->FormatInput(inputBuffer, inputBuffer);
- }
- tag += inputBuffer;
- inputBuffer = "";
- std::regex base32Pattern("[^a-zA-Z2-7]");
- while (inputBuffer.empty()) {
- str->Input(inputBuffer, "Please enter the secret:");
- str->FormatInput(inputBuffer, inputBuffer);
- inputBuffer = std::regex_replace(inputBuffer, base32Pattern, "");
- }
- secret = inputBuffer;
- std::transform(secret.begin(), secret.end(), secret.begin(), ::toupper);
- str->Input(inputBuffer, "Please enter the period (default 30):");
- if (str->FormatInput(inputBuffer, period, '2')) {
- if (period < 1) period = 30;
- }
- else {
- period = 30;
- }
- str->Input(inputBuffer, "Please select the hash algorithm:\n[1] SHA-1\n[2] SHA-256\n[3] SHA-384\n[5] SHA-512\nEnter your choice (default 1):");
- if (inputBuffer == "2") {
- alg = '2';
- } else if (inputBuffer == "3") {
- alg = '3';
- } else if (inputBuffer == "5") {
- alg = '5';
- }
- str->Input(inputBuffer, "Please enter the digits (between 6 - 10, default 6):");
- if (str->FormatInput(inputBuffer, digits, '2')) {
- if ((digits < 6) || digits > 10) digits = 6;
- }
- else {
- digits = 6;
- }
- tOTP_object tOTPInstance;
- tOTPInstance.tag = tag; tOTPInstance.secret = secret; tOTPInstance.period = period; tOTPInstance.alg = alg; tOTPInstance.digits = digits;
- tOTPObjects += tOTPInstance;
- return;
- }
+ void Add(std::vector& tOTPObjects) {
+ auto str = std::make_unique_for_overwrite();
+ std::string inputBuffer, tag, secret;
+ char alg = '1';
+ unsigned int period;
+ unsigned short digits;
+ while (inputBuffer.empty()) {
+ str->Input(inputBuffer, "Please enter the issuer (e.g., GitHub), then hit Enter TWICE to proceed:", true);
+ str->FormatInput(inputBuffer, inputBuffer);
+ }
+ tag = inputBuffer + "::";
+ inputBuffer = "";
+ while (inputBuffer.empty()) {
+ str->Input(inputBuffer, "Please enter the account (e.g., user@example.com), \nthen hit Enter TWICE to proceed:", true);
+ str->FormatInput(inputBuffer, inputBuffer);
+ }
+ tag += inputBuffer;
+ inputBuffer = "";
+ std::regex base32Pattern("[^a-zA-Z2-7]");
+ while (inputBuffer.empty()) {
+ str->Input(inputBuffer, "Please enter the secret:");
+ str->FormatInput(inputBuffer, inputBuffer);
+ inputBuffer = std::regex_replace(inputBuffer, base32Pattern, "");
+ }
+ secret = inputBuffer;
+ std::transform(secret.begin(), secret.end(), secret.begin(), ::toupper);
+ str->Input(inputBuffer, "Please enter the period (default 30):");
+ if (str->FormatInput(inputBuffer, period, '2')) {
+ if (period < 1) period = 30;
+ }
+ else {
+ period = 30;
+ }
+ str->Input(inputBuffer, "Please select the hash algorithm:\n[1] SHA-1\n[2] SHA-256\n[3] SHA-384\n[5] SHA-512\nEnter your choice (default 1):");
+ if (inputBuffer == "2") {
+ alg = '2';
+ } else if (inputBuffer == "3") {
+ alg = '3';
+ } else if (inputBuffer == "5") {
+ alg = '5';
+ }
+ str->Input(inputBuffer, "Please enter the digits (between 6 - 10, default 6):");
+ if (str->FormatInput(inputBuffer, digits, '2')) {
+ if ((digits < 6) || digits > 10) digits = 6;
+ }
+ else {
+ digits = 6;
+ }
+ str.reset();
+ tOTP_object tOTPInstance;
+ tOTPInstance.tag = tag; tOTPInstance.secret = secret; tOTPInstance.period = period; tOTPInstance.alg = alg; tOTPInstance.digits = digits;
+ tOTPObjects += tOTPInstance;
+ return;
+ }
}
\ No newline at end of file
diff --git a/src/actions/generatetotp.cpp b/src/actions/generatetotp.cpp
index 60a334f..58bfe74 100644
--- a/src/actions/generatetotp.cpp
+++ b/src/actions/generatetotp.cpp
@@ -11,7 +11,7 @@
#include
namespace ACTIONS {
- std::string GenerateTOTP(tOTP_object& tOTP) {
+ std::string GenerateTOTP(tOTP_object& tOTP) {
auto secretSize = static_cast(floor(tOTP.secret.size() / 1.6));
unsigned char* decodedSecret = new unsigned char[secretSize];
TOOLS::Base32Decode(tOTP.secret, decodedSecret);
@@ -25,5 +25,5 @@ namespace ACTIONS {
delete[] HMACDigest; delete HMACDigestSize;
std::string paddedResult = "0000000000" + std::to_string(result);
return paddedResult.substr(paddedResult.length() - tOTP.digits);
- }
+ }
}
\ No newline at end of file
diff --git a/src/include/actions/add.h b/src/include/actions/add.h
index fb8c5aa..b64b1d8 100644
--- a/src/include/actions/add.h
+++ b/src/include/actions/add.h
@@ -8,7 +8,7 @@
#include
namespace ACTIONS {
- void Add(std::vector& tOTPObjects);
+ void Add(std::vector& tOTPObjects);
}
#endif
diff --git a/src/include/actions/generatetotp.h b/src/include/actions/generatetotp.h
index 916814b..5c3d557 100644
--- a/src/include/actions/generatetotp.h
+++ b/src/include/actions/generatetotp.h
@@ -8,7 +8,7 @@
#include
namespace ACTIONS {
- std::string GenerateTOTP(tOTP_object& tOTP);
+ std::string GenerateTOTP(tOTP_object& tOTP);
}
#endif