Write a program to validate a password using the following rules:
• The password must be at least six characters in length
• It must contain at least one uppercase letter.
• It must contain at least one lowercase letter.
• It must contain at least one digit (0-9).
must contain this below
int validate(string pw);
//Validates password and returns a code, 0 if valid
// and 1 through 15 indicating the reason or combination of
// reasons that it is invalid
string findReason(int code);
// Accepts a reason code and returns a string indicating
// that it was valid or the reason why it wasn’t.
void display(string result);
//Accepts a string indicating the status of the password
//and displays it.
I get error num2 is used without being initialized and if you guys could, fix my coding if i did something wrong thank you....
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
|
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int validate(string passward);
string findReason(int code);
void display(string result);
int main()
{
int code, check = 0;
string passward, result;
bool validornot;
do{
cout << "Enter the Passward" << endl;
cin >> passward;
cout << passward << endl;
check = validate(passward);
code = validate(passward);
result = findReason(code);
display(result);
if (check == 1)
validornot = false;
else
validornot = true;
} while (validornot);
return 0;
}
int validate(string passward)
{
int num1,num2,num3,num4,num5,num6;
int number;
char ch;
ch = passward[0];
if (passward.length() < 6)
{
if (isalpha(ch))
num1 = 1;
if (isdigit(ch))
num2 = 1;
if (ch == tolower(ch))
num3 = 1;
if (ch == toupper(ch))
num4 = 1;
//valid
if (num1 == 1 && num2 == 1 && num3 == 1 && num4 == 1)
number = 1;
//missing one thing
if (num1 == 1 && num2 == 1 && num3 == 1)
number = 2;
if (num1 == 1 && num2 == 1 && num4 == 1)
number = 3;
if (num1 == 1 && num3 == 1 && num4 == 1)
number = 4;
if (num2 == 1 && num3 == 1 && num4 == 1)
number = 5;
//missing two thing
if (num1 == 1 && num2 == 1)
number = 6;
if (num1 == 1 && num3 == 1)
number = 7;
if (num1 == 1 && num4 == 1)
number = 8;
if (num2 == 1 && num3 == 1)
number = 9;
if (num2 == 1 && num4 == 1)
number = 10;
if (num3 == 1 && num4 == 1)
number = 11;
//missing three thing
if (num1 = 1)
number = 12;
if (num2 = 1)
number = 13;
}
else
{
number = 0;
}
return number;
}
string findReason(int code)
{
string validnot;
if (code == 0)
validnot = "Invalid less than 6 character";
if (code == 1)
validnot = "Valid!";
if (code == 2)
validnot = "Invalid No Upper Case!";
if (code == 3)
validnot = "Invalid No Lower Case!";
if (code == 4)
validnot = "Invalid No Digit!";
if (code == 5)
validnot = "Invalid No Alphabet";
if (code == 6)
validnot = "Invalid No Upper or Lower";
if (code == 7)
validnot = "Invalid No Digit and Upper ";
if (code == 8)
validnot = "Invalid no Digit or Lower";
if (code == 9)
validnot = "Invalid No Alphabet";
if (code == 10)
validnot = "Invalid No Alphabet";
if (code == 11)
validnot = "Invalid No Digit and Alphabet";
if (code == 12)
validnot = "Invalid No Digit or Upper or Lower";
if (code == 13)
validnot = "No Alphabet";
return validnot;
}
void display(string result)
{
cout << result << endl;
}
|