Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <iostream>
- using namespace std;
- bool validateLength(string);
- bool validateLowerCase(string);
- bool validateUpperCase(string);
- int main()
- {
- string input;
- bool validInput = false;
- while(!validInput)
- {
- cout<<"Enter password!"<<endl;
- cin>>input;
- bool validLength = validateLength(input);
- bool validLowerCase = validLength && validateLowerCase(input);
- bool validUpperCase = validLowerCase && validateUpperCase(input);
- validInput = validLength && validLowerCase && validUpperCase;
- }
- cout << "done!";
- }
- bool validateLength(string input)
- {
- if (input.length()< 7)
- {
- cout << "Password must be longer than 7";
- return false;
- }
- return true;
- }
- bool validateLowerCase(string input)
- {
- int position = -1;
- for(char lowerCase='a'; lowerCase < 'z'; lowerCase ++)
- {
- position = input.find(lowerCase);
- if (position > -1)
- {
- return true;
- }
- }
- cout <<"Password must contain lower case";
- return false;
- }
- bool validateUpperCase(string input)
- {
- int position = -1;
- for(char upperCase='A'; upperCase < 'Z'; upperCase ++)
- {
- position = input.find(upperCase);
- if (position > -1)
- {
- return true;
- }
- }
- cout<< "Password must contain upper case";
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment