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
55 lines (50 loc) · 1.13 KB
/
Password.cpp
File metadata and controls
55 lines (50 loc) · 1.13 KB
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
#include "Password.h"
#include <cctype>
#include <set>
#include <string>
using std::string;
/*
The function receives a string counts how many times the same character
occurs at the beginning of the string, before any other characters (or the
end of the string). The function is case-sensitive so 'Z' is different than
'z' and any ASCII characters are allowed.
*/
int Password::count_leading_characters(string phrase){
if (phrase.empty())
{
return 0;
}
int repetition = 1;
string::size_type index = 0;
while( index < phrase.length()-1 && phrase[index] == phrase[index+1] ){
repetition++;
index++;
}
return repetition;
}
unsigned int Password::unique_characters(string str)
{
std::set<char> seen;
for (char ch : str)
{
seen.insert(ch);
}
return seen.size();
}
bool Password::has_mixed_case(string str)
{
bool has_lower = false;
bool has_upper = false;
for (char ch : str)
{
if (std::islower(static_cast<unsigned char>(ch)))
{
has_lower = true;
}
else if (std::isupper(static_cast<unsigned char>(ch)))
{
has_upper = true;
}
}
return has_lower && has_upper;
}