forked from ChicoState/UnitTestPractice
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPassword.cpp
75 lines (60 loc) · 1.24 KB
/
Password.cpp
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
#include "Password.h"
#include <string>
#include <vector>
using std::string;
int Password::count_leading_characters(string phrase){
int repetition = 0;
if(phrase != "")
repetition = 1;
int index = 0;
while( index < phrase.length()-1 && phrase[index] == phrase[index+1] ){
repetition++;
index++;
}
return repetition;
}
bool Password::has_mixed_case(string temp)
{
bool hasUpper = false;
bool hasLower = false;
for(int i = 0; i < temp.length(); i++)
{
if(std::isupper(temp[i]))
hasUpper = true;
if(std::islower(temp[i]))
hasLower = true;
}
if(hasUpper && hasLower)
return true;
else
return false;
}
Password::Password()
{
pass_history.push_back("ChicoCA-95929");
};
void Password::set(string temp)
{
if(temp.length() >= 8 || temp.length() <= 20)
{
if(count_leading_characters(temp) <= 3)
{
bool hasUpperAndLower = has_mixed_case(temp);
if(hasUpperAndLower)
{
bool isUnique = authenticate(temp);
if(isUnique)
{
pass_history.push_back(temp);
}
}
}
}
}
bool Password::authenticate(string temp)
{
bool isUnique = true;
if(temp == pass_history[pass_history.size()])
isUnique = false;
return isUnique;
}