- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Strong Password Suggester Program
Every year on 7th May the worldwide organizations remind there users about the significance of a strong password. As per the tech giant Google;
24% of their end users have used the word "password" or "Qwerty" as their account password.
While, only 34% from their total users change their account passwords in a frequent manner.
In this tech-forward world today, every login attempt has a chance of a cyber criminal attack. But many people now a days still using the weak passwords for their professional and personal accounts.
Here we will discuss and check, whether the created passwords are very weak, weak, moderate, strong or very strong. And for that we will go through the password creation criteria as per the algorithm. In this article today, we will learn how to create a strong password suggester by using a C++ code.
How to create a strong password - Algorithm
Here is the general algorithm for a strong password. It helps a developer to develop a password suggester system in a C++ environment and find the particular criteria of their password.
Step 1 − Start
Step 2 − The length of an ideal password should be at least eight characters.
Step 3 − Must contain at least a digit character.
Step 4 − There should be at least one lowercase character. [Example: a,b,c.....,z]
Step 5 − There should be at least one uppercase character. [Example: A,B,C......,Z]
Step 6 − It should contain at least one special character. [Example: !@#$ %^&*()-+]
Step 7 − End
Creating a strong password suggester - Syntax
switch (k) { case 1: if ((count_alphabet == 7) && (count_number == 0 || count_ALPHABET == 0 || count_ALPHABET == 7 || count_s_symbol == 0)) break; key = getKey(); password = password + alphabet[key]; count_alphabet++; count++; break; case 2: if ((count_ALPHABET == 7) && (count_number == 0 || count_alphabet == 0 || count_alphabet == 5 || count_s_symbol == 0)) break; key = getKey(); password = password + ALPHABET[key]; count_ALPHABET++; count++; break; case 3: if ((count_number == 7) && (count_alphabet == 0 || count_alphabet == 1 || count_ALPHABET == 3 || count_ALPHABET == 0 || count_s_symbol == 0)) break; key = getKey(); key = key % 10; password = password + number[key]; count_number++; count++; break; case 4: if ((count_s_symbol == 1) && (count_alphabet == 0 || count_alphabet == 1 || count_ALPHABET == 0 || count_ALPHABET == 1 || count_number == 0)) break; key = getKey(); key = key % 6; password = password + s_symbol[key]; count_s_symbol++; count++; break; } cout << "\n-----------------------------\n"; cout << " Enter The Password \n"; cout << "------------------------------\n\n"; cout << " " << password add here; cout << "\n\n Press any key continue \n"; getchar(); }
Here in this syntax, the condition checks the minimum requirements of an ideal password. We have divided every possible condition into four cases where it checks the requirement of alphabet, number and special symbol character has been fulfilled or not as per the minimum requirements. And other characters still left after the process and then it will break.
Approach – to create a strong password suggester
Approach 1 − Create a strong password suggester environment
Approach 2 − Check the password is strong, weak or moderate
Approach 3 − Check your password with conditions
Create a strong password suggester environment
In this C++ build code, the system will check the strength of the input data (password). It will scan the input for all mentioned criteria of an ideal password. If all the criteria matches then it is an ideal password. Else, any character absent in the input, it will return some random generated password.
Example 1
#include <bits/stdc++.h> using namespace std; string add_more_char(string str, int need){ int pos = 0; string low_case = "abcdefghijklmno"; for (int a = 0; a < need; a++) { pos = rand() % str.length(); str.insert(pos, 1, low_case[rand() % 26]); } return str; } string suggester(int m, int o, int a, int d, string str) { string num = "0123456789"; string low_case = "abcdefghijklmno"; string up_case = "ABCDEFGHIJKLMNO"; string spl_char = "@#$_()!*&%#+-=.`"; int pos = 0; if (m == 0) { pos = rand() % str.length(); str.insert(pos, 1, low_case[rand() % 26]); } if (o == 0) { pos = rand() % str.length(); str.insert(pos, 1, up_case[rand() % 26]); } if (a == 0) { pos = rand() % str.length(); str.insert(pos, 1, num[rand() % 10]); } if (d == 0) { pos = rand() % str.length(); str.insert(pos, 1, spl_char[rand() % 7]); } return str; } void generate_password(int n, string p){ int l = 0, u = 0, d = 0, s = 0, need = 0; string suggest; for (int j = 0; j < n; j++) { if (p[j] >= 97 && p[j] <= 122) l = 1; else if (p[j] >= 65 && p[j] <= 90) u = 1; else if (p[j] >= 48 && p[j] <= 57) d = 1; else s = 1; } if ((l + u + d + s) == 4) { cout << "Hurra! Your Passcode Is Strong, Go Ahead!" << endl; return; } else cout << "Suggested password As Per The Input. Pick One For You! " << endl; for (int i = 0; i < 10; i++) { suggest = suggester(l, u, d, s, p); need = 8 - suggest.length(); if (need > 0) suggest = add_more_char(suggest, need); cout << suggest << endl; } } int main(){ string input_string = "abonirudra@1607"; srand(time(NULL)); generate_password(input_string.length(), input_string); return 0; }
Output
Suggested password As Per The Input. Pick One For You! abonirudGra@1607 abConirudra@1607 abonirudra@1E607 abonirudra@16A07 abonirudra@160L7 abNonirudra@1607 aNbonirudra@1607 abonirDudra@1607 aboniruFdra@1607 abonirNudra@1607
Check if the password is strong, weak, or moderate
As per the mentioned algorithm and C++ build code; the encoded string checks the input strength. The whole method returns the "Strong" as the output when the all conditions has been satisfied. If it satisfied the first three steps only and length of the password at least eight characters then it will return as "Moderate".
Example 2
#include <bits/stdc++.h> using namespace std; void printStrongNess(string& input) { int n = input.length(); bool hasLower = false, hasUpper = false; bool hasDigit = false, specialChar = false; string normalChars = "abcdefghijklmnopqrstu" "vwxyzABCDEFGHIJKL023456789 "; 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 = "Abonirudra@22052023"; printStrongNess(input); return 0; }
Output
Strength of password:-Strong
Check your password with the conditions
Here in this code we will perform the validation operation for a particular password. Here are the particular steps −
Take input from a user.
User input will now be check for the password combination.
The password is classified as strong, moderate, and weak.
If the all conditions are true then it will be a strong password.
Else, moderate or weak.
Example 3
#include <bits/stdc++.h> using namespace std; void checkpassword(string& password) { int n = password.length(); bool hasLower = false, hasUpper = false, hasDigit = false; for (int i = 0; i < n; i++) { if (islower(password[i])) hasLower = true; if (isupper(password[i])) hasUpper = true; if (isdigit(password[i])) hasDigit = true; } cout << "Strength of password you have entered as per the input :-"; if ( hasUpper && hasDigit && hasLower && (n >= 6)) cout << "Strong" << endl; else if ((hasLower || hasUpper) && hasDigit && (n >=6)) cout << "Moderate" << endl; else cout << "Weak" << endl; } int main() { cout << "Welcome To The Password Tester! Let's Check Your Password. " << endl; cout << "Let's consider the average length of an ideal strong password should be more than 6 character " << endl; cout << "Please enter your desired password with :- " << endl; cout << " * at least one upper case letter and lower case letter " << endl; cout << " * and also need to have at least one digit " << endl; string password; cout <<"Enter your monermoto password"<<endl; getline(cin,password); checkpassword(password); return 0; }
Output
Welcome To The Password Tester! Let's Check Your Password. Let's consider the average length of an ideal strong password should be more than 6 character Please enter your desired password with :- * at least one upper case letter and lower case letter * and also need to have at least one digit Enter your monermoto password Strength of password you have entered as per the input :-Weak
Conclusion
From this article we found how to create a password suggester environment by using C++ and then with that particular platform how we can evaluate out password quality with some tags (Strong, Moderate , Weak).