Program Help Login and Asterisk
Feb 8, 2017 at 12:38am UTC
Please guys help me with this, disregard the bottom part, what I just need to take care of right now is the log-in process, the password should be in asterisk and the limit of login attempts should only be three. I can't seem to make it work like when you get the password correct it transfers you to the menu.
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
#include<iostream>
#include<string>
#include<stdlib.h>
#include<conio.h>
using namespace std;
int main()
{
system ("color 7" );
cout <<" **************************************************************** " <<endl;
cout <<" **************************************************************** " <<endl;
cout <<" ******************* *** **** *** ********************* " <<endl;
cout <<"*********************** ** ** **** *** *************************" <<endl;
cout <<"*********************** ** ** ******** *****************************" <<endl;
cout <<"*********************** ****** ********* ******************************" <<endl;
cout <<"*********************** ****** ********* ******************************" <<endl;
cout <<"******************************************************************************" <<endl;
cout <<"******************************************************************************" <<endl;
cout <<"******************************************************************************" <<endl;
cout <<"** ** ** ** ** ** ** ***** ** *******" <<endl;
cout <<"** ** ** ** ** ** ** ****** ** ***** ** *******" <<endl;
cout <<"** ** ** ** ******* ***** ** ** ** ***** ** ** *******" <<endl;
cout <<"** ***** ** ** ***** ***** ****** ** ***** ** *******" <<endl;
cout <<"** ***** ** **** *** ***** ****** ** ** ** *******" <<endl;
cout <<"******************************************************************************" <<endl;
cout <<"******************************************************************************" <<endl;
cout <<"******************************************************************************" <<endl;
cout <<"******************************************************************************" <<endl;
cout <<" ****************************************************************** " <<endl;
cout <<endl;
cout <<endl;
const int max_attempts=3;
string username;
string password;
char c;
int attempts = 0;
for (int attempts = 0; attempts < max_attempts; attempts++)
{
START:
cout <<" User has 3 trials" <<endl;
cout <<" Enter Username: " ;
cin >>username;
cout <<" Enter Password: " ;
char pass[32];
int i = 0;
char a;
for (i=0;;)
{
a=getch();
if ((a>='a' &&a<='z' )||(a>='A' &&a<='Z' )||(a>='0' &&a<='9' ))
{
pass[i]=a;
++i;
cout<<"*" ;
}
if (a=='\b' &&i>=1)
{
cout<<"\b \b" ;
--i;
}
if (a=='\r' )
{
pass[i]='\0' ;
break ;
}
}
if (username=="1234" || password=="12345" )
{goto loop2;}
else {
cout << "Unsuccessful login " << max_attempts - attempts - 1 << " attempts more.\n" ;
}
system("cls" );
loop2:
string answer;
cout <<" MAIN MENU\n" ;
cout <<"\nchoose the letter for each topic to view some sample program: \nBasic in c++: " ;
cout <<" \n a.variables" ;
cout <<" \n b.constant" ;
cout <<" \n c.operators" ;
cout <<" \n d.basic input/output" ;
cout <<" \n e.control structure" ;
cout <<" \n f.arrays" ;
cout <<" \n g.Exit" ;
cout <<endl;
cout <<endl;
cout <<"Please Enter the letter you choose: " ;
cin >> answer;
if (answer == "a" )
{
system("cls" );
string variable;
cout <<"VARIABLE in C++ is name for a piece of memory that can be used to store informa-tion" <<endl;
cout <<" \n a. identifier, data types, declaration, and introduction of variables" ;
cout <<" \n b. introduction of strings" ;
cout <<" \n c. go back to main menu" ;
cout <<" \n d. Exit" ;
cout <<endl;
cout <<"Please Enter the letter you choose: " ;
cin >>variable;
}
if (answer == "b" )
{
string constant;
cout <<"CONSTANT expression with a fixed value" <<endl;}
}
system ("PAUSE" );
return 0;
}
Feb 8, 2017 at 1:52am UTC
Input password 3 times, and the password appears to be all asterisks whatever the user inputs it?
So I wish you luck. This topic is for advanced C++ programmers only. I might want to do it but implementing such thing is time-consuming.
Feb 8, 2017 at 1:54am UTC
The program runs the password in asterisk characters it is already solved. But the main problem here is even if the password is wrong it still goes inside the menu.
Feb 8, 2017 at 1:54am UTC
Also the trials are fixed.
Feb 8, 2017 at 1:58am UTC
Your code does not look good and please get rid of goto . Code indentation is also important.
Last edited on Feb 8, 2017 at 2:00am UTC
Topic archived. No new replies allowed.