This repository has been archived by the owner on Jan 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jerry Ortega - Password Verifier
121 lines (101 loc) · 2.51 KB
/
Jerry Ortega - Password Verifier
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
#include <iostream>
#include <cstring>
#include <cctype>
#include <locale>
#define SIZE 100
using namespace std;
bool lengthTest(char pass[]);
bool lowCaseTest(char pass[]);
bool upCaseTest(char pass[]);
bool digitTest(char pass[]);
bool specialTest(char pass[]);
int main()
{
char password[SIZE];
bool valid = true;;
cout << "Jerry Ortega's Password Verifier\n" << endl;
cout << "INSTRUCTIONS: Minimum 7 characters. You need 1 lower case, 1 upper case, 1 number, and 1 special character\n" << endl;
cout << "Enter the password: ";
cin.getline(password, SIZE);
if (!lengthTest(password))
{
valid = false;
cout << "Password does not meet length criteria. Length should be min 7" << endl;
}
if (!lowCaseTest(password))
{
valid = false;
cout << "Password should contain atleast one lowercase character" << endl;
}
if (!upCaseTest(password))
{
valid = false;
cout << "Password should contain atleast one upper character" << endl;
}
if(!digitTest(password))
{
valid = false;
cout << "Password should contain atleast one digit" << endl;
}
if (!specialTest(password))
{
valid = false;
cout << "Password should contain atleast one non-alpha, non-digit, non-space, punctuation character" << endl;
}
if(valid)
{
cout << "The passowrd entered is valid" << endl;
}
return 0;
cin.get();
cin.ignore();
}
/* Tests if length of string is >= 7 or not */
bool lengthTest(char pass[])
{
int numChar = strlen(pass);
bool validlength = false;
if (numChar >= 7)
validlength = true;
return validlength;
}
/* Tests if password contains lowercase characters or not */
bool lowCaseTest(char pass[])
{
for (int cnt = 0; cnt < strlen(pass); cnt++)
{
if (islower(pass[cnt]))
return true;
}
return false;
}
/* Tests if password contains uppercase characters or not */
bool upCaseTest(char pass[])
{
for (int cnt = 0; cnt < strlen(pass); cnt++)
{
if (isupper(pass[cnt]))
return true;
}
return false;
}
/* Tests if password contains digits or not */
bool digitTest(char pass[])
{
for (int cnt = 0; cnt < strlen(pass); cnt++)
{
if (isdigit(pass[cnt]))
return true;
}
return false;
}
/* Tests if password contains special characters or not */
bool specialTest(char pass[])
{
for (int cnt = 0; cnt < strlen(pass); cnt++)
{
if (ispunct(pass[cnt]))
return true;
}
return false;
}