Advertisement
Guest User

Untitled

a guest
Mar 13th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.47 KB | None | 0 0
  1. // Abhishek Prasad
  2. // COSC 1410
  3. // Haberdar Tu-Th 8:30-10:00
  4. // March 13, 2016
  5.  
  6.  
  7.  
  8. #include <iostream>
  9. using namespace std;
  10.  
  11.  
  12.  
  13.     int main()
  14. {
  15.     int unInput;    // declaring variables for Input for Password and Username
  16.     int pwInput;
  17.     int UN = 123456; // Username
  18.     int PW = 1234;  // temporary password
  19.  
  20.     for (int tries = 1; tries < 4; tries ++)
  21.         {
  22.        
  23.         cout << "Enter Username: ";
  24.         cin >> unInput;
  25.        
  26.         cout << "Enter Password ";
  27.         cin >> pwInput;
  28.        
  29.         if (unInput == UN && pwInput == PW)     // if statement - checks if pw and un are correct. if true, the
  30.         {
  31.             cout << "Congratulations! Now please enter your new password" << endl;
  32.            
  33.             bool match = false;
  34.            
  35.             do
  36.             {
  37.                 cout << "The new password must be a 4 digit number and different from the temporary password. Enter new password:" << endl;
  38.                
  39.                 cin >> pwInput;
  40.                
  41.                 if (pwInput > 999 && pwInput < 10000 && pwInput != PW)
  42.                     {
  43.                    
  44.                     PW = pwInput;
  45.                     cout << "You have changed your PW successfully! Please re-login."<<endl;
  46.                     match = true;
  47.                     }
  48.             } while (match != true);
  49.             break;  // breaks program
  50.         }
  51.         else    // if the program failed 3 times
  52.         {
  53.             cout << "Invalid credentials, program terminates after 3 falied attemps, number of failed tries= " << tries << endl;
  54.         }
  55.         if (tries == 3) // if tries are 3 it will run the following statement
  56.         {
  57.             cout << "The system cannot be accessed. The program has ended.";
  58.         }
  59.     }
  60.     for (int tries = 1; tries < 4; tries ++) // these statements run after the statement
  61.     {
  62.         cout << "Enter Username: ";
  63.         cin >> unInput;
  64.        
  65.         cout<< "Enter Username: ";
  66.         cin >> pwInput;
  67.        
  68.         if (unInput == UN && pwInput == PW)
  69.         {
  70.             cout << "Access granted! Enjoy :)";
  71.             break;
  72.         }
  73.         else
  74.         {
  75.             cout << "Wrong password. Number of tries left: " << tries << endl;
  76.         }
  77.        
  78.         if (tries == 3)
  79.        
  80.         {
  81.             cout << "The system cannot be accessed. The program has ended."<<endl;
  82.         }
  83.     }
  84.     return 0;
  85. }
  86.  
  87. // end of program :)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement