搜尋
首頁後端開發C++強密碼建議程序

強密碼建議程序

Sep 01, 2023 pm 04:53 PM
密碼產生器密碼強度評估密碼策略實施

強密碼建議程序

每年 5 月 7 日,全球組織都會提醒使用者強程式碼的重要性。根據科技巨頭谷歌的說法;

  • 他們的終端使用者中有24%將單字"password"或"Qwerty"作為他們的帳號密碼。

  • 雖然,只有34%的使用者經常更改他們的帳號密碼。

在當今這個技術先進的世界中,每次登入嘗試都有可能遭受網路犯罪攻擊。但現在許多人仍然在其專業和個人帳戶中使用弱密碼。

在這裡,我們將討論和檢查所建立的密碼是非常弱、弱、中等、強還是非常強。為此,我們將按照演算法的要求來檢查密碼的建立標準。在今天的文章中,我們將學習如何使用C 程式碼建立一個強密碼建議器。

如何建立強密碼 - 演算法

這是一個強密碼的通用演算法。它可協助開發者在C 環境中開發密碼建議系統,並找到密碼的特定標準。

  • 步驟 1 − 開始

  • #步驟 2 - 理想密碼的長度應至少為八個字元。

  • 步驟 3 − 必須包含至少一個數字字元。

  • 第四步 - 至少應該要有一個小寫字母。 [範例:a,b,c.....,z]

  • 第五步 - 至少應該有一個大寫字母。 [例:A,B,C......,Z]

  • 步驟 6 − 它應該包含至少一個特殊字元。 [範例:!@#$ %^&*()- ]

  • 第 7 步 - 結束

建立一個強密碼建議者 - 語法

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();
}

在這個語法中,條件檢查了一個理想密碼的最低要求。我們將每個可能的條件分為四種情況,檢查是否滿足了字母、數字和特殊符號字元的要求,以及是否滿足了最低要求。在處理過程中,如果還有其他字元剩下,那麼它將會被忽略。

方法 - 建立一個強密碼建議者

  • 方法 1 - 建立強密碼建議環境

  • 方法 2 - 檢查密碼是強、弱還是中

  • #方法三 - 檢查密碼是否符合條件

建立一個強密碼建議環境

在此 C 建構程式碼中,系統將檢查輸入資料(密碼)的強度。它將掃描輸入以查找理想密碼的所有提到的標準。如果所有條件都匹配,那麼它就是一個理想的密碼。否則,輸入中缺少任何字符,它將返回一些隨機生成的密碼。

Example 1

的中文翻譯為:

範例 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;
}

輸出

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

檢查密碼強度是否強、弱或中等

根據上述演算法和C 建立程式碼;編碼字串檢查輸入強度。當滿足所有條件時,整個方法會傳回“Strong”作為輸出。如果僅滿足前三個步驟並且密碼長度至少為八個字符,則它將返回“中等”。

Example 2

的中文翻譯為:

範例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;
}

輸出

Strength of password:-Strong

根據條件檢查您的密碼

在這段程式碼中,我們將對特定密碼進行驗證操作。以下是具體的步驟 -

  • 接受使用者的輸入。

  • 現在將檢查使用者輸入的密碼組合。

  • 密碼分為強、中、弱三種。

  • 如果所有條件都為真,則它將是一個強密碼。

  • 其他情況下,中等或弱。

Example 3

的中文翻譯為:

範例 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;
}

輸出

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

結論

從本文中,我們了解如何使用 C 建立密碼建議器環境,然後在該特定平台上如何使用一些標籤(強、中等、弱)評估密碼品質。

以上是強密碼建議程序的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文轉載於:tutorialspoint。如有侵權,請聯絡admin@php.cn刪除
C在現代世界中:應用和行業C在現代世界中:應用和行業Apr 23, 2025 am 12:10 AM

C 在現代世界中的應用廣泛且重要。 1)在遊戲開發中,C 因其高性能和多態性被廣泛使用,如UnrealEngine和Unity。 2)在金融交易系統中,C 的低延遲和高吞吐量使其成為首選,適用於高頻交易和實時數據分析。

C XML庫:比較和對比選項C XML庫:比較和對比選項Apr 22, 2025 am 12:05 AM

C 中有四種常用的XML庫:TinyXML-2、PugiXML、Xerces-C 和RapidXML。 1.TinyXML-2適合資源有限的環境,輕量但功能有限。 2.PugiXML快速且支持XPath查詢,適用於復雜XML結構。 3.Xerces-C 功能強大,支持DOM和SAX解析,適用於復雜處理。 4.RapidXML專注於性能,解析速度極快,但不支持XPath查詢。

C和XML:探索關係和支持C和XML:探索關係和支持Apr 21, 2025 am 12:02 AM

C 通過第三方庫(如TinyXML、Pugixml、Xerces-C )與XML交互。 1)使用庫解析XML文件,將其轉換為C 可處理的數據結構。 2)生成XML時,將C 數據結構轉換為XML格式。 3)在實際應用中,XML常用於配置文件和數據交換,提升開發效率。

C#vs. C:了解關鍵差異和相似之處C#vs. C:了解關鍵差異和相似之處Apr 20, 2025 am 12:03 AM

C#和C 的主要區別在於語法、性能和應用場景。 1)C#語法更簡潔,支持垃圾回收,適用於.NET框架開發。 2)C 性能更高,需手動管理內存,常用於系統編程和遊戲開發。

C#與C:歷史,進化和未來前景C#與C:歷史,進化和未來前景Apr 19, 2025 am 12:07 AM

C#和C 的歷史與演變各有特色,未來前景也不同。 1.C 由BjarneStroustrup在1983年發明,旨在將面向對象編程引入C語言,其演變歷程包括多次標準化,如C 11引入auto關鍵字和lambda表達式,C 20引入概念和協程,未來將專注於性能和系統級編程。 2.C#由微軟在2000年發布,結合C 和Java的優點,其演變注重簡潔性和生產力,如C#2.0引入泛型,C#5.0引入異步編程,未來將專注於開發者的生產力和雲計算。

C#vs. C:學習曲線和開發人員的經驗C#vs. C:學習曲線和開發人員的經驗Apr 18, 2025 am 12:13 AM

C#和C 的学习曲线和开发者体验有显著差异。1)C#的学习曲线较平缓,适合快速开发和企业级应用。2)C 的学习曲线较陡峭,适用于高性能和低级控制的场景。

C#vs. C:面向對象的編程和功能C#vs. C:面向對象的編程和功能Apr 17, 2025 am 12:02 AM

C#和C 在面向对象编程(OOP)中的实现方式和特性上有显著差异。1)C#的类定义和语法更为简洁,支持如LINQ等高级特性。2)C 提供更细粒度的控制,适用于系统编程和高性能需求。两者各有优势,选择应基于具体应用场景。

從XML到C:數據轉換和操縱從XML到C:數據轉換和操縱Apr 16, 2025 am 12:08 AM

從XML轉換到C 並進行數據操作可以通過以下步驟實現:1)使用tinyxml2庫解析XML文件,2)將數據映射到C 的數據結構中,3)使用C 標準庫如std::vector進行數據操作。通過這些步驟,可以高效地處理和操作從XML轉換過來的數據。

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

將Eclipse與SAP NetWeaver應用伺服器整合。

Dreamweaver Mac版

Dreamweaver Mac版

視覺化網頁開發工具

SublimeText3 英文版

SublimeText3 英文版

推薦:為Win版本,支援程式碼提示!

MantisBT

MantisBT

Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

WebStorm Mac版

WebStorm Mac版

好用的JavaScript開發工具