English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Usando C ++Programa para verificar a força da senha

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 are told whether the password is easy to guess or crack. The strength should vary from weak, moderate, and strong.

  • The password length must be at least8characters.

  • It must contain1lowercase.

  • It must contain1uppercase

  • It must contain a digit

  • It must contain a special character, such as: !@#$%^&*> < , .+ =-

is like having a password "w3codebox”is easy to guess, so we can conclude that the password "weak" he provided is because it only contains lowercase letters, while the password "w3codebox @ 863!” which has both uppercase and lowercase letters, numbers, and special characters, and has robustness, and its length is greater than8characters, therefore meeting all the conditions that make the password stronger.

If some passwords meet more than half of the characteristics of a strong password, then we will consider the password to be moderate. Like the password "w3codebox12It will be considered moderate because it contains lowercase letters, a digit, and its length is greater than8characters.

Exemplo

Input: w3codebox!@12
Output: Password strength:-Strong
Explanation: Password has 1 lowercase, 1 uppercase, 1 special character, more than 8 characters long and a digit, hence the password is strong.
Input: w3codebox
Output: Password strength:-Weak

The method we will use to solve the given problem-

  • Output the string as the password.

  • Check if all the factors can be used to determine the strength of the password.

  • Print the strength of the password based on the factors.

Algorithm

Start
   Passo 1 ⇒ In function void printStrongNess(string& input)
      Declare and initialize n = input.length()
      Declarar bool hasLower = false, hasUpper = false
      Declarar bool hasDigit = false, specialChar = false
      Declarar string normalChars = "abcdefghijklmnopqrstu"
      "vwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"1234567890 "
      Loop For i = 0 e i < n e i++
         Se (islower(input[i]))
            Definir hasLower = true
         Se (isupper(input[i]))
            Definir hasUpper = true
         Se (isdigit(input[i]))
            Definir hasDigit = true
            Definir size_t special = input.find_first_not_of(normalChars)
         Se (special != string::npos)
            Definir specialChar = true
      Fim do Loop
      Imprimir "Força da senha:"-"
      Se (hasLower && hasUpper && hasDigit &&
         specialChar && (n >= 8))
         Imprimir "Forte"
      else if ((hasLower || hasUpper) &&
            specialChar && (n >= 6))
         Imprimir "Moderada"
      else
         print "Fraca"
   Passo 2 ⇒ Em função int main() Declara e inicializa input = "w"3codebox!@12"
      printStrength(input)
Parar

Exemplo

#include <iostream>
using namespace std;
void printStrength(string& input) {
   int n = input.length();
   //Verificar letras minúsculas na string
   bool hasLower = false, hasUpper = false;
   bool hasDigit = false, specialChar = false;
   string normalChars = "abcdefghijklmnopqrstu" "vwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"1234567890 ";}}
   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;
   }
   //Password strength
   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 = "w3codebox!@12";
   printStrongNess(input);
   return 0;
}

Output result

Strength of password:-Moderate