Advertisement
Guest User

Untitled

a guest
Jul 15th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     string pass;
  9.     cout << "Your password must contain a number and capital letter." << endl;
  10.     cout << "Enter your password: ";
  11.     getline(std::cin, pass);
  12.     int i, l, up, low, dig;
  13.     /*These are flag variables*/
  14.     up = low = dig = 0;
  15.     /*Initially all are set to 0 i.e false*/
  16.     l = pass.length();
  17.     for (i = 0; i < l; i++)
  18.     {
  19.         /*Digit condition*/
  20.         if (pass[i] >= '0' && pass[i] <= '9')
  21.             dig = 1;
  22.         else
  23.             /*Uppercase condition*/
  24.             if (pass[i] >= 'A' && pass[i] <= 'Z')
  25.                 up = 1;
  26.         /*Lowercase condition*/
  27.         if (pass[i] >= 'a' && pass[i] <= 'z')
  28.             low = 1;
  29.     }
  30.  
  31.     /*4 conditions to form the password*/
  32.     if (l >= 6 && dig == 1 && up == 1 && low == 1)
  33.     {
  34.         cout << "Your password meets the stated criteria.\n";
  35.     }
  36.     else
  37.     {
  38.         cout << "Sorry !\n";
  39.  
  40.         if (l < 6)
  41.         {
  42.             cout << "Your password is less than 6 characters.\n";
  43.         }
  44.         else if (!up)
  45.         {
  46.             cout << "Your password does not contain uppercase letters.\n";
  47.         }
  48.         else if (!dig)
  49.         {
  50.             cout << "Your password does not contain any digits.\n";
  51.         }
  52.         else if (!low)
  53.         {
  54.             cout << "Your password does not contain lowercase letters.\n";
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement