Program to check Strength of Password | C ++ program to check if a given password is strong or not . ; Checking lower alphabet in string ; Strength of password ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void printStrongNess ( string & input ) { int n = input . length ( ) ; bool hasLower = false , hasUpper = false ; bool hasDigit = false , specialChar = false ; string normalChars = " abcdefghijklmnopqrstu " " vwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 ▁ " ; 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_of ( normalChars ) ; if ( special != string :: npos ) specialChar = true ; } 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 = " GeeksforGeeks ! @12" ; printStrongNess ( input ) ; return 0 ; }