if (choose == "1") //----------->> FOR SIGNUP <<-----------//
{
do
{
//----------------------->> SIGNUP PAGE <<-----------------------//
cin.ignore ();
system ("CLS");
cout << "====================SIGNUP====================" <<
endl;
cout << "FIRST NAME: ";
getline (cin, fname1);
cout << "LAST NAME: ";
getline (cin, lname1);
cout << "USERNAME: ";
cin >> uname;
for (int cun = 0; cun < counter; cun++)
{
if (uname == username1[cun])
{
system ("CLS");
cout << endl;
cout <<
" The username is aldready taken! Please try again."
<< endl;
cout << endl;
cout <<
"====================================================="
<< endl;
cout << endl;
cout << "Press 1 and enter to continue: ";
cin >> choose1;
returntoSignupPage = true;
break;
}
else
{
if (cun == (counter - 1))
{
if (username.is_open ())
{
username << user1 << endl;
}
if (firstname.is_open ())
{
firstname << fname1 << endl;
}
if (lastname.is_open ())
{
lastname << lname1 << endl;
}
cout << "PASSWORD: ";
cin >> pass1;
if (password.is_open ())
{
password << pass1 << endl;
}
cout << endl;
system ("CLS");
cout <<
"====================================================="
<< endl;
cout << endl;
cout <<
" You have succesfully created your account"
<< endl;
cout << endl;
cout <<
"====================================================="
<< endl;
cout << endl;
cout << "Press 1 and enter to go to Home Page: ";
cin >> choose1;
HomePage = true;
returntoSignupPage = false;
break;
}
returntoSignupPage = false;
}
}
}
while (returntoSignupPage);
}
else if (choose == "2")
{
//------------------>> LOGIN PAGE <<------------------//
do
{
system ("CLS");
cout << "====================LOGIN====================" << endl;
cout << "Username: ";
cin >> user1;
for (int check = 0; check < counter; check++)
{
if (user1 == username1[check])
{
//------->> This is to get the name of the user correcty<<-------//
if (check == counter - 1)
{
check1 = check;
}
else
{
check1 = check;
}
//------------------------------------------------------//
do
{
cout << "Password: ";
cin >> pass1;
if (pass1 == pass2[check])
{
cout << endl;
system ("CLS");
cout <<
"=============================================================="
<< endl;
cout << endl;
cout << "\t \t You have succesfully login.\t "
<< endl;
cout << endl;
cout <<
"=============================================================="
<< endl;
cout << "Enter any number to continue: ";
cin >> choose1;
cout << endl;
filename = user1 + txt;
validLogin = true;
redo2 = false;
if (invalid == 3)
{
system ("CLS");
cout << endl;
cout <<
"You have reach the maximum retries!" <<
endl;
cout << endl;
cout <<
"==================================================="
<< endl;
cout <<
"Press 1 and enter to go to Home Page: ";
cin >> choose2;
redo2 = false;
invalid = 0;
}
}
}
while (redo2);
redo3 = false;
break;
}
else
{
if (check == (counter - 1))
{
system ("CLS");
cout << endl;
cout << "Username Not Found! Please try again." <<
endl;
cout << endl;
cout <<
"==================================================="
<< endl;
cout << "Enter any number to continue: ";
cin >> choose2;
redo3 = true;
invalid++;
if (invalid == 3)
{
system ("CLS");
cout << endl;
cout << "You have reach the maximum retries!" <<
endl;
cout << endl;
cout <<
"==================================================="
<< endl;
cout <<
"Press 1 and enter to go to Home Page: ";
cin >> choose2;
redo3 = false;
invalid = 0;
break;
}
}
}
}
}
while (redo3);
HomePage = true;
if (validLogin == true)
{
HomePage = false;
}
}
}
return 0;
}
I'm getting this error :
main.cpp:367:11: error: expected ‘while’ before numeric constant
367 | return 0;
| ^
main.cpp:367:11: error: expected ‘(’ before numeric constant
367 | return 0;
| ^
| (
main.cpp:367:12: error: expected ‘)’ before ‘;’ token
367 | return 0;
| ~^
| )
Does anyone know how to fix it? and how to improve my login system.
welcome!
please put code tags around this, edit your post and highlite the code part then hit the <> on the sidebar or type code and /code inside [] brackets to block the code part off. It is too big for plain text viewing.
while(redo3); //infinite loop
I believe you have a do-while loop that is missing the while part.
the first thing to improve is to get rid of the redo 1/2/3 and stop repeating the same blocks of code. Loop 3 times (for loop), and if they fail 3 times, tell them to go away.
consider
bool loggedin{};
for(int try = 0; try < 3 && !loggedin; try++)
{
get user and password, see if it is correct
if correct, loggedin = true (or, slightly better if it is possible and readable, loggedin = (user==good && password == good) without the extra explicit if statement)
}
if(loggedin) //after the loop logic
{
allow access to something
}
else
{
tell them to go away, too many tries and blah blah.
}
if you want to get fancy, once you have this much working, you can try encrypting the file on the computer.