Loop? Problem in Login features..

Hey guys, I got a slight problem here which I can't solve it.

I made a login feature which requires user to enter their id and password.

After enter his id, the user will be prompt whether to encrpyt his password using caesar cipher 4.
If it fails to login 3 times. Account it "locked"

The problem I facing now is..
User can login without encrypting the password.
However, when he select encrypt, login fail the first time, but it pass the 2nd time.
Anyone knows what's going on?

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
33
34
35
36
37
38
39
40
41
42
void Login::loginMenu(){
        string idInput;
        string pwInput;
        int sel ;
        int attempts = 0;
        string idText;
        string pwText;
        int i = 0;
        int ccEncrypt = 4;

        while(attempts<3){ 
        ifstream loginData("login.txt");
        loginData >> idText;
        loginData >> pwText;
        cin.ignore();
        cout << endl << "Enter login name: ";
        getline(cin,idInput);
        pwInput = getpass("Enter password: ");
        cout<<"Do you want to encrypt?"<<endl;
        cout<<"[1] Yes"<<endl;
        cout<<"[2] No"<<endl;
        cin >> sel;        
        if(sel==1){
        while(i < pwText.length())
        {
        pwText[i] = int(pwText[i]) - ccEncrypt;
        i++;
        }//end loop
        }//end if
        if(idInput == idText && pwInput == pwText){
        PCMF mainMenu;
        cout << "Login Success!!" << endl;
        mainMenu.menu();
        }//end if   
        else{       
        cout << "Login Fail!!" << endl;
        attempts++;
        }//end else
        }//end loops
        cout << "Your account is locked, please try again later." << endl;
        loginMenu();
        }//end loginMenu login 
bump
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
33
34
35
36
37
38
39
40
41
void Login::loginMenu(){
   string idInput;
   string pwInput;
   int sel ;
   int attempts = 0;
   string idText;
   string pwText;
   int i = 0;
   int ccEncrypt = 4;

   while(attempts<3){ 
      ifstream loginData("login.txt");
      loginData >> idText;
      loginData >> pwText;
      cin.ignore();
      cout << endl << "Enter login name: ";
      getline(cin,idInput);
      pwInput = getpass("Enter password: ");
      cout<<"Do you want to encrypt?"<<endl;
      cout<<"[1] Yes"<<endl;
      cout<<"[2] No"<<endl;
      cin >> sel;        
      if(sel==1) {
         while(i < pwText.length()) {
            pwText[i] = int(pwText[i]) - ccEncrypt;
            i++;
         }//end loop
      }//end if
      if(idInput == idText && pwInput == pwText){
         PCMF mainMenu;
         cout << "Login Success!!" << endl;
         mainMenu.menu();
      }//end if   
      else{       
         cout << "Login Fail!!" << endl;
         attempts++;
      }//end else
   }//end loops
   cout << "Your account is locked, please try again later." << endl;
   loginMenu();
}//end loginMenu login  

Indentation is your friend.

Though I don't understand your code. Of course a string that matches non encrypted password will not match the encrypted one. The idea is to store the encrypted password in a file and encrypt user input..
Topic archived. No new replies allowed.