Skip to content

Commit

Permalink
refactor: fix variable assignments
Browse files Browse the repository at this point in the history
  • Loading branch information
ni-jessica committed Oct 21, 2023
1 parent 3ddab34 commit 19290cc
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions backend/src/passwords.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "passwords.hpp";
#include <iostream>
#include "passwords.hpp"

namespace passwords
{
Expand All @@ -7,7 +8,8 @@ namespace passwords
int minChars = 10;

if (maxChars < minChars) {
return;
std::cout << "Password must have a minimum length of 10 characters\n";
exit(0);
}

std::unordered_set<std::string> passwords;
Expand All @@ -26,38 +28,39 @@ namespace passwords
for (int i = 0; i < length; i++)
{
int charType = rand() % 4;
int index;
switch (charType)
{
case 0: // lowercase letter
hasLowercase = true;
if (!(hasLowercase && hasUppercase && hasDigit && hasSymbol)){
break;
}
int index = rand() % lowercase.length();
index = rand() % lowercase.length();
password = password + lowercase[index];
break;
case 1: // uppercase letter
hasUppercase = true;
if (!(hasLowercase && hasUppercase && hasDigit && hasSymbol)) {
break;
}
int index = rand() % uppercase.length();
index = rand() % uppercase.length();
password = password + uppercase[index];
break;
case 2: // digit
hasDigit = true;
if (!(hasLowercase && hasUppercase && hasDigit && hasSymbol)) {
break;
}
int index = rand() % digits.length();
index = rand() % digits.length();
password = password + digits[index];
break;
case 3: // symbol
hasSymbol = true;
if (!(hasLowercase && hasUppercase && hasDigit && hasSymbol)) {
break;
}
int index = rand() % symbols.length();
index = rand() % symbols.length();
password = password + symbols[index];
break;
};
Expand Down

0 comments on commit 19290cc

Please sign in to comment.