You are on page 1of 4

Problem number 6

new
#include<iostream>
#include<string> // #0 missing header
#include<string.h>
#include<conio.h>
using namespace std;
int main()
{
string _pass;
//char input = '\0'; // #2 warning C4700: uninitialized local variable 'input'
used
string yesno;
int i=0;
int j=0;
//char c; // #1 warning C4101: 'c' : unreferenced local variable
system("color 7d");

do
{
cout<<"\n Welcome, Please Enter Your Password to
continue"<<endl;
for(i=0;i<3;++i) // #5 was 5
{
_pass.clear(); // #3 reset password
cout<<"\n\t Password: ";
char input = '\0'; // #4 move inside loop

while (input != 13)


{
input = (char)getch();
if(input == 13)
break;
j++;
_pass += input;
cout << "*";
}

if(_pass=="haha")
{
cout<<"\n\n\t\t"<<"Welcome, Sir
"<<endl;
system("PAUSE");
system("cls");
break;
}
else // #6 reformat
{
if(i==2) // #7 was >2
return false;
}
}

cout <<"Try Again?. <y/n> \n\t\t";


cin>>yesno;
}
while(yesno=="y");
{
cout<<"EXITING PROGRAM!"<<endl;
cin.get();
system("pause");
return 0;
}
// #8 warning C4702: unreachable code
//system ("PAUSE");
//return 0;
}

ex.1
#include <iostream>
#include <string>
#include<cctype>
using namespace std;
bool myIsDigit(string); //prototypes
bool myIsUpper(string);
bool myIsLower(string);
int main()
{
string password, verbose;
int sec1, sec2;
cout << "Password Strength Checker!"<<endl;
cout << endl;
cout << "Enter the password to check: ";
cin >> password;
cout << "Enter the two security codes: ";
cin >> sec1 >> sec2;
cout << "Verbose? (y/n) ";
cin >>verbose;
cout << "--------------------------------------"<<endl;
cout << "Checking " << password <<" " << sec1 << " " << sec2 << endl;
return 0;
}
bool myIsDigit(string password)
{
if((password.size() >=8) && (password.size()<=14))
return true;
else
return false;
}
bool myIsUpper(string password)

{
if(((password.0) >= 'A') && ((password.0) <= 'Z'))
return true;
else
return false;
}
bool myIsLower(string password)
{
if ( password.1 >= 'A' && password.1 <= 'Z')&&( password.2>= 'A' && password.2
<= 'Z')
return true;
else
return false;
}

EXAMPLE #2
#include <iostream.h>
#include <stdlib.h>
#include <string>
using namespace std;

void enterPassword();
void reenterPassword();

string password1;
string password2;
int password1_length;
bool valid_length = false;
bool passwords_match = false;

int main()
{
do
{
cout << "Enter a password: ";
cin >> password1;
enterPassword(); //function call
}
while (valid_length = false);
do
{
cout << "Re-enter your password: ";
cin >> password2;
reenterPassword(); //function call
}
while (passwords_match = false);
system("PAUSE");
return 0;
}
void enterPassword() //function definition
{
password1_length = password1.length();

if ( password1_length >=8 && password1_length <= 16 )


{
valid_length = true;
}

else
{
valid_length = false;
}
}

void reenterPassword() //function definition


{
if ( password1 != password2 )
{
passwords_match = true;
}

else
{
passwords_match = false;
}
}

You might also like