I am setting up a sign up, and login program, but it never allows to login. At the time of execution, it displays entering two characters while the user types only one, and also at the time of login the password never matches. Any solutions for goto.
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
int i, t = 3;
struct dateob {
int day;
int month;
int year;
};
struct userdetails {
char name[50];
dateob dob;
char country[100];
char residential_address[100];
char office_address[100];
char citizen_proof[100];
long phoneno;
char gender[10];
long money;
char username[100];
char password[100];
};
userdetails ud[3];
char u[100], u1[100];
void Entering(char a, int n)
{
if (a == 'S')
{
cout << "Username ";
cin.ignore();
cin.getline(ud[n].username, 100);
string user = ud[n].username;
cout << "Password ";
for (i = 0; i < 100; i++)
{
ud[n].password[i] = _getch();
if (ud[n].password[i] == 13)
break;
cout << "*";
}
cout << "\n"
<< "User Created\n";
goto login;
}
else if (a == 'L')
{
login:
char username[100], password[100];
cout << "Welcome To Login";
for (int j = 0; j <= 3; j++)
{
cout << "Username ";
cin.ignore();
cin.getline(username, 100);
cout << "Password ";
for (i = 0; i < 100; i++)
{
password[i] = _getch();
if (password[i] == 13)
break;
cout << "*";
}
if (strcmp(username, ud[n].username) == 0 && strcmp(password, ud[n].password) == 0)
{
cout << "You can Enter :)";
break;
}
else
{
cout << "\nSomething went wrong! \n";
cout << "You Left with" << t-- << "Try \n";
}
}
if (t == 0)
cout << "You are Suspicious";
}
}
int main()
{
char a, b, c;
int d;
for (int n = 0; n < 3; n++)
{
cout << "Do you want to enter users :Y/N ";
cin >> b;
if (b == 'Y')
{
cout << "Sign Up : S \n"
<< "Login : L \n";
cin >> a;
Entering(a, n);
}
else
break;
}
return 0;
}
I entered only 2 characters from keyboard but it displays 4 characters.You can see screenshot of result here I expected that it takes the password, and store it, and then can be used as an reference for Login.