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
|
#include <iostream>
#include <cstring>
#include <cctype>
#include <string>
using namespace std;
void validate(char *);
bool upper(char *, int size);
bool lower(char*, int size);
bool num(char*,int size);
bool length(char*);
int main()
{
const int size = 30;
char password[size];
/*char *passPtr = password;*/
cout << "Enter a password that is more " <<endl;
cout << "than 6 characters " << endl;
cout << "long, less than 20 characters and the password " << endl;
cout << "must include an uppercase letter, a " << endl;
cout << "lower case letter and a number." << endl;
cin.getline(password, size);
length(password);
cout << password << endl;
if (length(password) == false)
{
cout << "Password is either too long or does not contain enough characters." << endl;
}
upper(password, size);
if(upper(password, size) == false)
{
cout << "Password does not contain an uppercase letter." <<endl;
}
lower(password, size);
if(lower(password, size)== false)
{
cout << "Password does not contain a lower case letter." << endl;
}
num(password, size);
if (num(password,size) == false)
{
cout << "Password does contain a number." << endl;
}
return 0;
}
bool length(char * password)
{
int length;
bool passlength = false;
length = strlen(password);
if (length <= 6 || length >= 20)
{
passlength = false;
}
else
{
passlength = true;
}
return passlength;
}
bool upper(char * password, int size)
{
int length = strlen(password);
bool up = true;
for (int k = 0; k < length; k++)
{
if (isupper(password[k]))
{
up = true;
}
else
up = false;
}
return up;
}
bool lower(char * password, int size)
{
int length = strlen(password);
bool low = false;
for (int j = 0; j < length; j++ )
{
if(islower(password[j]))
{
low = true;
}
else
{
low = false;
}
}
return low;
}
bool num(char * password, int size)
{
int length = strlen(password);
bool num = false;
for (int i = 0; i < length; i++ )
{
if(isdigit(password[i]))
{
num = true;
}
else
{
num = false;
}
}
return num;
}
|