C ++ implements password strength testing to achieve password strength
Recently, I have seen many js-based password strength tests in my blog. I think this is quite interesting. So I plan to write a script for fun on my own. The most sad thing is that I haven't learned js yet, of course this is not important, so I plan to use C ++ to write a password strength test. Here I will tell you what is different from what is written in JS and in C ++.
JS-written password strength detection: when you enter a string> = 6 digits, the strength of the password is automatically displayed, if you continue to enter the password, the password strength will change. (Of course, I have tried to solve this problem and I can only enter 6 digits after writing it. Due to my limited technology, if you can write it on your own, try it );
C ++ password Strength Check: when you enter a string> = 6 digits, you must press enter to read the string into the memory, in this way, there is a certain gap between JS and JS.
Next, let's look at the password strength detection rules;
* 1) any combination of characters between 1 and 6 is weak. For example, win
* 2) a combination of two types of characters in any number, for example, win123
* 3) a combination of three or four types of characters below 12 characters, strong; for example, win123abcABC
* 4) a combination of three or four types of characters with 12 or more characters is very good. Example: win123abcABC!
Idea: Write a sub-function and traverse the search stringUppercaseAndLowercaseAndNumberAnd so onOther charactersWhether a character exists. Here we remember that if a character exists, it is counted only once. Then return to the main function. The main function mainly determines the composition of several types of Characters in the password and then outputs the password strength according to the corresponding number;
The following code is used:
1 # include <iostream> 2 # include <cstring> 3 # include <cctype> 4 using namespace std; 5 int fun (char password []); 6 int main (int argc, char * argv []) 7 {8 int I; 9 char password [16]; 10 stop: cout <"Password:"; gets (password ); 11 while (strlen (password)> = 6 & strlen (password) <= 16) {12 switch (fun (password) 13 {14 case 1: cout <"weak★"<Endl; break; 15 case 2: cout <"★★"<Endl; break; 16 case 3: cout <" strong★★★"<Endl; break; 17 case 4: cout <" very good★★★★"<Endl; break; 18} cout <" Password: "; gets (password); 19} 20 cout <" Minimum Password 6 ~ Enter 16 bits: "<endl; goto stop; 21 return 0; 22} 23 int fun (char password []) 24 {25 int I, count = 0, a = 1, B = 1, c = 1; 26 27 for (I = 0; I <strlen (password); I ++) 28 if (a & islower (password [I]) count ++, a = 0; 29 else if (B & isupper (password [I]) count ++, B = 0; 30 else if (c & isdigit (password [I]) count ++, c = 0; 31 else if (! Islower (password [I]) &! Isupper (password [I]) &! Isdigit (password [I]) count ++; 32 return count; 33}
The following is a running result:
PS: If you have a better idea, you can try it by yourself. Thank you for reading it.