Username and Password

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);}

else
{cout <<endl<<endl<<" Access aborted...";Sleep(2000);}

system ("cls");

}while(user != "Isaac" || pass !="riot");

return 0;
}

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:
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
#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;
}
Why does it say undeclared cout and cin?
Says _clrscr() was not declared :(
bump
PLs where is _clrscr :( ??? If there is a predefined one i reallt want it !!!
Topic archived. No new replies allowed.