Skip to content

Commit

Permalink
feat: refactored c++ code and integrated database
Browse files Browse the repository at this point in the history
  • Loading branch information
stellaljung committed Oct 23, 2023
1 parent c1fae6c commit e951cca
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
6 changes: 1 addition & 5 deletions backend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,4 @@ set (TEST_SOURCE

add_executable(${PROJECT_NAME} ${TEST_SOURCE})

target_link_libraries(${PROJECT_NAME} PRIVATE Catch2::Catch2WithMain)

target_include_directories(${PROJECT_NAME} PRIVATE tests)

include(Catch)
target_link_libraries(${PROJECT_NAME} PRIVATE Catch2::Catch2WithMain)
2 changes: 1 addition & 1 deletion backend/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ int main()
db.execute("CREATE TABLE passwords (password TEXT);");

// generate and insert the passwords into the database
std::unordered_set<std::string> passwordSet = password::generatePasswords(100, 20);
std::unordered_set<std::string> passwordSet = password::generatePasswords(10, 20);
for (const auto &password : passwordSet)
{
db.execute("INSERT INTO passwords (password) VALUES ('" + password + "');");
Expand Down
12 changes: 9 additions & 3 deletions backend/src/password.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ namespace password
{
const int min_chars = 10;

if (max_chars < min_chars)
{
// ensure max_chars is greater than min_chars
try {
if (max_chars < min_chars)
{
throw (max_chars);
}
}
catch (int max_chars) {
std::cout << "Password must have a minimum length of 10 characters\n";
exit(0);
std::cout << "You inputted a maximum length of " << max_chars << " characters \n";
}

std::unordered_set<std::string> passwords;
Expand Down
2 changes: 1 addition & 1 deletion backend/src/password.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace password
*
* @param numPasswords The number of passwords to generate.
* @param maxChars The maximum number of characters for a password.
* @return std::unordered_set<std::string>
* @return std::unordered_set<std::string> The passwords generated.
*/
std::unordered_set<std::string> generatePasswords(int num_passwords, int max_chars);
}
Expand Down

0 comments on commit e951cca

Please sign in to comment.