forked from ChicoState/UnitTestPractice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPassword.cpp
More file actions
47 lines (36 loc) · 882 Bytes
/
Password.cpp
File metadata and controls
47 lines (36 loc) · 882 Bytes
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
#include "Password.h"
#include <string>
#include <cctype>
using std::string;
int Password::count_leading_characters(string phrase){
if (phrase.length() == 0) return 0;
int repetition = 1;
int index = 0;
while(index < (int)phrase.length() - 1 &&
phrase[index] == phrase[index + 1]) {
repetition++;
index++;
}
return repetition;
}
bool Password::has_mixed_case(string pass){
bool hasUpper = false;
bool hasLower = false;
for (char c : pass){
if (std::isupper((unsigned char)c)) hasUpper = true;
if (std::islower((unsigned char)c)) hasLower = true;
}
return hasUpper && hasLower;
}
unsigned int unique_characters(string str){
bool seen[256] = {false};
unsigned int count = 0;
for (char c : str){
unsigned char uc = (unsigned char)c;
if (!seen[uc]){
seen[uc] = true;
count++;
}
}
return count;
}