Guest User

Some C++ code

a guest
Nov 18th, 2014
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.41 KB | None | 0 0
  1. #include <string>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. bool validateLength(string);
  6. bool validateLowerCase(string);
  7. bool validateUpperCase(string);
  8. int main()
  9. {
  10.        
  11.   string input;
  12.   bool validInput = false;
  13.   while(!validInput)
  14.   {
  15.         cout<<"Enter password!"<<endl;
  16.         cin>>input;
  17.         bool validLength = validateLength(input);
  18.         bool validLowerCase = validLength && validateLowerCase(input);
  19.         bool validUpperCase = validLowerCase && validateUpperCase(input);
  20.         validInput = validLength && validLowerCase && validUpperCase;
  21.   }
  22.   cout << "done!";
  23. }
  24.  
  25. bool validateLength(string input)
  26. {
  27.     if (input.length()< 7)
  28.     {
  29.         cout << "Password must be longer than 7";
  30.         return false;
  31.     }
  32.     return true;
  33. }
  34.  
  35. bool validateLowerCase(string input)
  36. {
  37.     int position = -1;
  38.     for(char lowerCase='a'; lowerCase < 'z'; lowerCase ++)
  39.     {
  40.         position = input.find(lowerCase);
  41.         if (position > -1)
  42.         {
  43.             return true;
  44.         }
  45.     }
  46.     cout <<"Password must contain lower case";
  47.     return false;
  48. }
  49.  
  50. bool validateUpperCase(string input)
  51. {
  52.     int position = -1;
  53.     for(char upperCase='A'; upperCase < 'Z'; upperCase ++)
  54.     {
  55.         position = input.find(upperCase);
  56.         if (position > -1)
  57.         {
  58.             return true;
  59.         }
  60.     }
  61.     cout<< "Password must contain upper case";
  62.     return false;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment