1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
|
#include <iostream>
#include <string>
#include <fstream>
#include"Header.h"
using namespace std;
void bubblesort(std::string list[], const int &size)
{
string temp;
int iteration;
int index;
for (iteration = 1; iteration < size; iteration++)
{
for (index = 0; index < size - iteration; index++)
{
if (list[index] > list[index + 1])
{
temp = list[index];
list[index] = list[index + 1];
list[index + 1] = temp;
}
}
}
}
void beginprogram()
{
cout << " Hello user. This is a password program that will help you come up with a"
<< " strong non-common password."
<< "\n Some general rules for creating a strong non-common password are: \n"
<< " 1. No spaces.\n"
<< " 2. At least one captial letter.\n"
<< " 3. At least one number. \n"
<< " 4. No other special charaters other than ! $ % or ? should be used. \n"
<< " 5. At least 8 or more characters long. \n"
<< "\n Let us begin. Please enter a password: ";
}
//This is the function that detects spaces in the user's
//entered password.
bool searchspace(string key)
{
return key.find(' ') != string::npos;
}
//This is the function that checks the user's password
//to make sure it is at least eight characters or more.
bool searchlength(string key)
{
int ans = key.length();
if (ans >= 8)
return true;
else return false;
}
//This is the function that makes sure that there is at
//least one captial letter in the user's password.
bool searchuppercase(string key)
{
return key.find_first_of("ABCDEFGHIJKLMNOPQRSTUVWXYZ") != string::npos;
}
//This is the function that looks for at least one
//numerical character in the user's password.
bool searchnumber(string key)
{
return key.find_first_of("1234567890") != string::npos;
}
//This is the function that sends back true or false on
//whether the user's password contains one of the four
//special characters stated in the rules.
bool searchspecial(string key)
{
return key.find_first_of("!$%?") != string::npos;
}
bool searchWRONGspecial(string key)
{
return key.find_first_of("@#^&*()-_=+[]{}\|;:',.<>/") != string::npos;
}
bool strengthBoosterNumOrder(string key)
{
return key.find_first_of("012" || "123" || "234" || "345" || "456" || "567" || "678" || "789" || "890") != string::npos;
}
bool strengthBoosterPassSize18(string key)
{
int ans = key.length();
if (ans >= 18)
return true;
else return false;
}
bool strengthBoosterPassSize12(string key)
{
int ans = key.length();
if (ans >= 12)
return true;
else return false;
}
//uses the binary search to find if the user password is
//similar to the list of common passwords.
bool exactMatch(string key, string list[], int size)
{
/*for (int j = 0; j < size; j++)
{
key[j] = tolower(key[j]);
}*/
int first = 0;
int last = size - 1;
int mid;
bool found = false;
while (first <= last&&!found)
{
mid = (first + last) / 2;
if (list[mid] == key)
found = true;
else if (list[mid] > key)
last = mid - 1;
else
first = mid + 1;
}
return (found);
}
/*//This function compares the user's password with the
//loaded file of common passwords.
bool SubStringSearch(std::string key, std::string list[], int size)
{
for (int i = 0; i < size; i++)
{
if (key.find(list[i]) != string::npos)
return true;
}
return false;
}*/
//set function for class password, sets the private password to whatever password given
void password ::setpassword(string pass)
{
pass=userpassword;
}
//get function for class password, returns the password inputted
string password::getpassword()
{
return userpassword;
}
int password::getactualListSize()
{
return actualListSize;
}
//this determines whether a password is weak, strong, or between
void strength(string key, string list[], int ghostsize)
{
int strength = 0;
bool ematch = exactMatch(key, list, ghostsize);
bool sspace = !searchspace(key);
bool slength = !searchlength(key);
bool supcase = !searchuppercase(key);
bool snum = !searchnumber(key);
bool sspecial = !searchspecial(key);
bool swspecial = !searchWRONGspecial(key);
bool sbnumorder = !strengthBoosterNumOrder(key);
bool sbps18 = strengthBoosterPassSize18(key);
bool sbps12 = strengthBoosterPassSize12(key);
if (ematch)
{
strength++;
cout << "/n It's best not to use complete words.";
}
if (sspace)
{
strength++;
cout << "/n No spaces.";
}
if (slength)
{
strength++;
cout << "/n Password should be at least eight characters long.";
}
if (supcase)
{
strength++;
cout << "/nbPassword should have at least one uppercase letter.";
}
if (snum)
{
strength++;
cout << "/n Password should have at least one number.";
}
if (sspecial)
{
strength++;
cout << "/n ! $ % or ? should be used.";
}
if (swspecial)
{
strength++;
cout << "/n No other special charaters other than ! $ % or ? should be used.";
}
if (sbnumorder) { strength++; }
if (sbps18) { strength++; }
if (sbps12) { strength++; }
if (strength > 7)
{
cout << "/n Exceeds requirements. Strong Password.";
}
if (strength == 7)
{
cout << "/n Minimum requirements met. Looks good.";
}
if (strength < 7)
{
cout << "/n Below minimum requirements. Weak password.";
}
}
//constructor for class password, opening file and reading into array also counting how many were read
password::password()
{
std::ifstream passWordFile;
passWordFile.open("passwords.txt");
if (!passWordFile)
{
std::cout << "Error!";
exit(1);
}
while (!passWordFile.eof())
{
passWordFile >> passarray[actualListSize++];
//ActualListSize++;
}
bubblesort();
}
//copy constructor
password::password(const password& passwordcopy)
{
actualListSize = passwordcopy.actualListSize;
passarray = new string[MAXPASSWORD];
for (int k = 0; k < actualListSize; k++)
{
passarray[k]= passwordcopy.passarray[k];
}
}
//deconstructor for class password
password::~password()
{
delete[] passarray;
}
|