Advertisement
ivanwidyan

Password Checker With 3 Attempts and Funtions

Oct 18th, 2016
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. bool PasswordCheck(string);
  6.  
  7. int main() {
  8.     int PasswordAttempts = 3;
  9.     string Password;
  10.     while (PasswordAttempts >= 0) {
  11.         cout << "Enter your password: ";
  12.         cin >> Password;
  13.         if (PasswordCheck(Password)) {
  14.             cout << "You granted an access!" << endl;
  15.             return 0;
  16.         }
  17.         else
  18.         {
  19.             cout << "Wrong, password! you have " << PasswordAttempts << " try attempts" << endl;
  20.             PasswordAttempts--;
  21.         }
  22.     }
  23.     cout << "You've tried too many attempts, you're blocked" << endl;
  24. }
  25.  
  26. bool PasswordCheck(string password) {
  27.     if (password == "test") {
  28.         return true;
  29.     }
  30.     else {
  31.         return false;
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement