CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <string>
#include <cctype>
bool isStrongPassword(const std::string& password) {
int numberCount = 0;
int specialCharCount = 0;
const std::string specialChars = "!@#$%&*";
// Check if the password has at least 7 characters
if (password.length() < 7) {
return false;
}
// Count numbers and special characters
for (char c : password) {
if (isdigit(c)) {
numberCount++;
}
if (specialChars.find(c) != std::string::npos) {
specialCharCount++;
}
}
// The password is strong if it has at least 2 numbers, 2 special characters, and length >= 7
return (numberCount >= 2 && specialCharCount >= 2);
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run