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

C를 사용하여 ++암호强度 확인 프로그램

给定包含密码字符的字符串输入,任务是检查密码的强度。

密码的强度是当您告诉您密码是容易猜到还是被破解时。强度应从弱,中等和强到不同。要检查强度,我们必须检查以下几点:

  • 密码长度必须至少为8个字符。

  • 它必须包含1小写字母。

  • 它必须包含1大写字母

  • 它必须包含一个数字

  • 它必须包含一个特殊字符,例如:!@#$%^&*> <,。+ =-

就像有一个密码“ w3codebox”很容易猜到一样,因此我们可以断定他给出的密码“弱”,因为它只包含小写字符,而密码“ w3codebox @ 863!” 既具有大写和小写字母,数字和特殊字符,又具有强壮性,并且长度大于8个字符,因此满足使密码更强的所有条件。

如果有一些密码满足强密码的一半以上的特征,那么我们将认为该密码是中等密码。就像密码“ w3codebox12”一样,它将被认为是中等程度的,因为包含小写字母,一个数字并且其长度大于8个字符。

예제

Input: w3codebox!@12
Output:密码强度:-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:密码强度:-Weak

我们将用来解决给定问题的方法-

  • 将字符串输出作为密码。

  • 检查密码中是否有所有因素可以判断密码强度。

  • 根据因素打印密码的强度。

算法

Start
   단계 1 ⇒ In function void printStrongNess(string& input)
      Declare and initialize n = input.length()
      bool hasLower = false, hasUpper = false
      bool hasDigit = false, specialChar = false
      string normalChars = "abcdefghijklmnopqrstu"
      "vwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"1234567890 "
      Loop For i = 0 and i < n and 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
      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"
   단계 2 ⇒ 함수 int main() 내에서 선언 및 초기화 input = "w"3codebox!@12"
      printStrongNess(input)
정지

예제

#include <iostream>
using namespace std;
void printStrongNess(string& input) {
   int n = input.length();
   //문자열의 소문자를 확인합니다
   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;
   }
   //비밀번호 강도
   cout << "비밀번호 강도:"-";
   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;
}

출력 결과

비밀번호 강도:-Moderate