Skip to content

Commit

Permalink
Fix code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
pi-314159 authored Jun 11, 2024
1 parent 85c3daa commit d0d30b7
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 71 deletions.
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions VisualStudio/Authenticator.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@
<ConformanceMode>true</ConformanceMode>
<LanguageStandard_C>stdc17</LanguageStandard_C>
<LanguageStandard>stdcpp20</LanguageStandard>
<Optimization>Full</Optimization>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand Down
5 changes: 2 additions & 3 deletions src/Authenticator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<tOTP_object> tOTPObjects;
Expand Down
107 changes: 54 additions & 53 deletions src/actions/add.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,57 +9,58 @@
#include <regex>

namespace ACTIONS {
void Add(std::vector<tOTP_object>& tOTPObjects) {
auto str = std::make_unique_for_overwrite<TOOLS::String>();
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., [email protected]), \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<tOTP_object>& tOTPObjects) {
auto str = std::make_unique_for_overwrite<TOOLS::String>();
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., [email protected]), \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;
}
}
4 changes: 2 additions & 2 deletions src/actions/generatetotp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <cmath>

namespace ACTIONS {
std::string GenerateTOTP(tOTP_object& tOTP) {
std::string GenerateTOTP(tOTP_object& tOTP) {
auto secretSize = static_cast<int>(floor(tOTP.secret.size() / 1.6));
unsigned char* decodedSecret = new unsigned char[secretSize];
TOOLS::Base32Decode(tOTP.secret, decodedSecret);
Expand All @@ -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);
}
}
}
2 changes: 1 addition & 1 deletion src/include/actions/add.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <totp.h>

namespace ACTIONS {
void Add(std::vector<tOTP_object>& tOTPObjects);
void Add(std::vector<tOTP_object>& tOTPObjects);
}

#endif
2 changes: 1 addition & 1 deletion src/include/actions/generatetotp.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <totp.h>

namespace ACTIONS {
std::string GenerateTOTP(tOTP_object& tOTP);
std::string GenerateTOTP(tOTP_object& tOTP);
}

#endif

0 comments on commit d0d30b7

Please sign in to comment.