I want to create a text file for first run carrying the password and use the code to check the entire string for the password entered previously. The current code returns true value for the 1st few alphabets even if the whole password isn`t entered.
int Manager::ManagerView1()
{
Passwordsearch:
system("cls");
string search;
int offset,ErrorVar;
string line;
ifstream Myfile;
Myfile.open("Password.txt");
cout << "Enter your Password :\n";
cin >> search;
if (Myfile.is_open())
{
while (!Myfile.eof())
{
getline(Myfile,line);
if ((offset = line.find(search, 0)) != string::npos)
{
cout << "Password Accepted ..\n";
system("pause");
}
else
{
cout << "Password Incorrect. \nPress\n 1.) Go back to the main screen\n 2.) Re-Enter Password \n";
cin >> ErrorVar;
if (ErrorVar == 1)
{
system("PAUSE");
return 1;
}
else if (ErrorVar == 2)
{
system("PAUSE");
system("cls");
goto Passwordsearch;
}
else
{
cout << "Wrong option !! Please try again\n";
system("PAUSE");
return 1;
}
}
}
}
}
This is the password file that i want to check the string from: