Umm. What's the problem with this? Can you help pls. Q~Q
If i'd input the correct username and password first, it says access granted, so it's okay. But if i'd incorrectly input it at the first trial , says access aborted(okay)
then( it loops)
if i'd input the correct user and pass, it says aborted again even though it's right Q~Q
--------------------------------------------
#include <string>
#include <conio.h>
#include <iostream>
using namespace std;
int main()
{
string user,pass ="";
char p;
do{
cout<<"U S E R N A M E: ";
cin>>user;
cout<<"P A S S W O R D: ";
p = _getch();
while(p != 13){pass.push_back(p);cout <<'~';p = _getch();}
if
(pass == "riot" and user == "Isaac")
{cout <<endl<<endl<<" Access granted :)";Sleep(2000);}
You need to reset 'pass' and 'user'. The easiest way would be to simply change your loop into an infinite loop and have the variables local, with 'break' statements to escape to escape the loop. Here is an example:
#include <iostream>
#include <string>
#include <conio.h>
#include <windows.h>
int main() {
// infinite loop
for (;;) {
std::string user;
std::string pass = "";
// input the username and password here
if (pass == "riot" && user == "Isaac") {
std::cout << "\nAccess Granted :)\n";
Sleep(2000);
break; // escape the loop
} else {
std::cout << "\nAccess Denied...\n";
Sleep(2000);
}
// System() is more evil than conio.h. Normally I'd recommend against
// conio.h anyway, but in your case, there is no easy method to do
// the password masking, so you may as well use it here.
_clrscr();
}
std::cout << "Random Important Data!\n";
return 0;
}