Home Online Compilers WhiteboardMe
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#
Réponds au quizz et tente de
gagner
BigDeal
Given a string input containing password
characters, the task is to check the strength of
the password.
The strength of the password is when you tell
that the password is whether easily guessed or
cracked. The strength should vary from weak,
average and strong. To check the strength we
have to check the following points −
Password must be at least 8
characters long.
It must contain 1 lower case
alphabet.
It must contain 1 uppercase alphabet
It must contain a digit
It must contain a special character
like : !@#$%^&*()><,.+=-
Like there is a password “tutorialspoint” which is
easily guessed so we can cay that he given
password is “weak” as it contains only lowercase
characters, whereas password
“Tutorialspoint@863!” is strong as have both
upper and lowercase, a digit and a special
character and is longer than 8 characters, hence
meeting all the conditions to make a password
stronger.
If there is some password meeting the more than
half of the characteristics of the strong password,
then we will consider the password as moderate.
Like the password “tutorialspoint12” it will be
considered as moderate as contains lowercase, a
digit and its length is greater than 8 chacters.
Example
Input: tutoriAlspOint!@12
Output: Strength of password:-Strong
Explanation: Password has 1 lowercase, 1 upperca
Input: tutorialspoint
Output: Strength of password:-Weak
Approach we will be using to solve the
given problem −
Take a string output for password.
Check the password for all the factors
which are responsible for judging the
password strength.
According to the factors print the
password’s strength.
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
Explore our latest online courses and learn
new skills at your own pace. Enroll and become a
certified expert to boost your career.
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
Updated on: 20-Nov-2019
7K+ Views
Related Articles
C# program to check password validity
C# program to check the validity of a
Password
Python program to check the validity of
a Password?
C++ Program to check whether given
password is strong or not
Program to check whether given
password meets criteria or not in
Python
Swift program to generate a password
Program to check bitnoicity of an array
in C++
Program to check idempotent matrix in
C++
Program to check Involutory Matrix in
C++
Strong Password Suggester Program
Random password generator in C
C# Program to Check status of Current
Thread
C++ Program to Check Multiplicability
of Two Matrices
C++ Program to Check Leap Year
C++ Program to Check Armstrong
Number
Kickstart Your Career
Get certified by completing the course
Get Started
Print Page Previous Next
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
Cloud Computing Tutorial
Amazon Web Services Tutorial
Microsoft Azure Tutorial
Git Tutorial
Ethical Hacking Tutorial
Docker Tutorial
Kubernetes Tutorial
DSA Tutorial
Spring Boot Tutorial
SDLC Tutorial
Unix Tutorial
CERTIFICATIONS
Business Analytics Certification
Java & Spring Boot Advanced Certification
Data Science Advanced Certification
Cloud Computing And DevOps
Advanced Certification In Business Analytics
Artificial Intelligence And Machine Learning
DevOps Certification
Game Development Certification
Front-End Developer Certification
AWS Certification Training
Python Programming Certification
COMPILERS & EDITORS
Online Java Compiler
Online Python Compiler
Online Golang Compiler
Online C Compiler
Online C++ Compiler
Online C# Compiler
Online PHP Compiler
Online MATLAB Compiler
Online Bash Compiler
Online SQL Compiler
Online Html Editor
ABOUT US | OUR TEAM | CAREERS | JOBS | CONTACT US |
TERMS OF USE | PRIVACY POLICY | REFUND POLICY |
COOKIES POLICY | FAQ'S
Tutorials Point is a leading Ed Tech company striving to
provide the best learning material on technical and non-
technical subjects.
© Copyright 2025. All Rights Reserved.