Password

I've made a program, and I want to password protect it, i.e. it would run only when the correct password is entered. . .
The password should be a string, e.g. raj.
And while entering, the a "*" should be printed instead of the characters entered. . .

Would anyone please help. . . ?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

void passwordcheck(){
string password, input;
password = "raj";

while (done != true){
       done = false;
       cout << "input password: ";
       getline(input);
       if (input != password)
              cout << "wrong password\n";
       else
              done = true;
       }
}

would you explain it a bit ?

btw, i've done it, but still interested in what you've written...
Basically, you make a loop that only allows you to exit when you've entered the correct string, which we have set to "raj". If the user enters anything else, the function starts over and prompts the user again.

1
2
3
4
5
6
7


int main(void){
      passwordcheck(); //this makes the user have to get the password before moving on

//rest of your main function

Topic archived. No new replies allowed.