Program To Check Strength of Password in C++
Program To Check Strength of Password in C++
Java
JSP
SQL HTML CSS Javascript Python
iOS
Program
HTML to check Strength of
Password in C++
Android
C++ Server Side Programming Programming
Python
C Programming
Réponds au
C++ Programming
quizz
C#
BigDeal
Example
Input: tutoriAlspOint!@12
Output: Strength of password:-Strong
Explanation: Password has 1 lowercase, 1 upperca
Input: tutorialspoint
Output: Strength of password:-Weak
Algorithm
Start
Step 1 In function void printStrongNess(string
Declare and initialize n = input.length()
Declare bool hasLower = false, hasUpper = fal
Declare bool hasDigit = false, specialChar = fa
Declare string normalChars = "abcdefghijklmn
"vwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123
Loop For i = 0 and i < n and i++
If (islower(input[i]))
Set hasLower = true
If (isupper(input[i]))
Set hasUpper = true
If (isdigit(input[i]))
Set hasDigit = true
Set size_t special = input.find_first_not_o
If (special != string::npos)
Set specialChar = true
End Loop
Print "Strength of password:-"
If (hasLower && hasUpper && hasDigit &&
specialChar && (n >= 8))
Print "Strong"
else if ((hasLower || hasUpper) &&
specialChar && (n >= 6))
Print "Moderate"
else
print "Weak"
Step 2 In function int main()
Declare and initialize input = "tutorialspoint!@
printStrongNess(input)
Stop
Example
#include <iostream>
using namespace std;
void printStrongNess(string& input) {
int n = input.length();
// Checking lower alphabet in string
bool hasLower = false, hasUpper = false;
bool hasDigit = false, specialChar = fal
string normalChars = "abcdefghijklmnopqr
for (int i = 0; i < n; i++) {
if (islower(input[i]))
hasLower = true;
if (isupper(input[i]))
hasUpper = true;
if (isdigit(input[i]))
hasDigit = true;
size_t special = input.find_first_not
if (special != string::npos)
specialChar = true;
}
// Strength of password
cout << "Strength of password:-";
if (hasLower && hasUpper && hasDigit &&
specialChar && (n >= 8))
cout << "Strong" << endl;
else if ((hasLower || hasUpper) &&
specialChar && (n >= 6))
cout << "Moderate" << endl;
else
cout << "Weak" << endl;
}
int main() {
string input = "tutorialspoint!@12";
printStrongNess(input);
return 0;
}
Output
Strength of password:-Moderate
Sunidhi Bansal
7K+ Views
Related Articles
C# program to check password validity
Get Started
Advertisements
TOP TUTORIALS
Python Tutorial
Java Tutorial
C++ Tutorial
C Programming Tutorial
C# Tutorial
PHP Tutorial
R Tutorial
HTML Tutorial
CSS Tutorial
JavaScript Tutorial
SQL Tutorial
TRENDING TECHNOLOGIES
Git Tutorial
Docker Tutorial
Kubernetes Tutorial
DSA Tutorial
SDLC Tutorial
Unix Tutorial
CERTIFICATIONS
DevOps Certification
Online C Compiler
Online C# Compiler