Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- string pass;
- cout << "Your password must contain a number and capital letter." << endl;
- cout << "Enter your password: ";
- getline(std::cin, pass);
- int i, l, up, low, dig;
- /*These are flag variables*/
- up = low = dig = 0;
- /*Initially all are set to 0 i.e false*/
- l = pass.length();
- for (i = 0; i < l; i++)
- {
- /*Digit condition*/
- if (pass[i] >= '0' && pass[i] <= '9')
- dig = 1;
- else
- /*Uppercase condition*/
- if (pass[i] >= 'A' && pass[i] <= 'Z')
- up = 1;
- /*Lowercase condition*/
- if (pass[i] >= 'a' && pass[i] <= 'z')
- low = 1;
- }
- /*4 conditions to form the password*/
- if (l >= 6 && dig == 1 && up == 1 && low == 1)
- {
- cout << "Your password meets the stated criteria.\n";
- }
- else
- {
- cout << "Sorry !\n";
- if (l < 6)
- {
- cout << "Your password is less than 6 characters.\n";
- }
- else if (!up)
- {
- cout << "Your password does not contain uppercase letters.\n";
- }
- else if (!dig)
- {
- cout << "Your password does not contain any digits.\n";
- }
- else if (!low)
- {
- cout << "Your password does not contain lowercase letters.\n";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement