[try Beta version]
Not logged in

 
Password

Dec 7, 2013 at 4:09pm
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. . . ?
Dec 9, 2013 at 7:15am
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;
       }
}

Dec 10, 2013 at 11:10am
would you explain it a bit ?

btw, i've done it, but still interested in what you've written...
Dec 11, 2013 at 9:43pm
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.