/// <Summary>
/// Determine whether it is a simple password. It cannot contain the same characters (such as aaa, 111), ascending sequence (abc, 123), and descending sequence (cda, 321)
/// </Summary>
/// <Param name = "strPassword"> password </param>
/// <Param name = "intTimes"> Number of identical or progressively decreasing characters </param>
/// <Returns> </returns>
Private static bool HaveSimpleCode (string strPassword, int intTimes)
{
# Region === basic parameter ===
System. Collections. ArrayList arrChar = new System. Collections. ArrayList ();
String strChar = "";
String strTempA = "";
String strTempB = "";
String strTempSameChar = "";
# Endregion
// Print all characters
For (int I = 0; I <strPassword. Length; I ++)
{
# Region === avoid repeated access for multiple times ===
StrChar = strPassword. Substring (I, 1 );
// Avoid repeated access for multiple times
If (! ArrChar. Contains (strChar ))
{
Arrchar. Add (strchar );
}
Else
{
Continue;
}
# Endregion
# Region === multiple identical characters ====
Strtempsamechar = "";
// Multiple identical characters
For (int k = 0; k <intTimes; k ++)
{
StrTempSameChar = strTempSameChar + strChar;
}
// If it contains multiple identical characters, return
If (strPassword. Contains (strTempSameChar ))
{
Return true;
}
# Endregion
# Region === whether the sequence has an ascending or descending number ====
System. Text. ASCIIEncoding asciiEncoding = new System. Text. ASCIIEncoding ();
Int intAsciiCode = (int) asciiEncoding. GetBytes (strChar) [0];
StrTempA = strChar;
StrTempB = strChar;
// 0--9 A--Z a -- z
If (intAsciiCode >=48 & intAsciiCode <= 58-intTimes) | (intAsciiCode >=65 & intAsciiCode <= 91-intTimes) | (intAsciiCode >=97 & intAsciiCode <= 123-intTimes ))
{
Int k = 1;
// Execute intTimes to construct the ABC or CBA, 123 or 321 string
While (k <intTimes)
{
Byte [] byteArray = new byte [] {(byte) (intAsciiCode + k )};
String strCharacter = asciiEncoding. GetString (byteArray );
StrTempA = strTempA + strCharacter;
StrTempB = strCharacter + strTempB;
K ++;
}
// Determine whether there is an ascending or descending sequence
If (strpassword. Contains (strtempa) | strpassword. Contains (strtempb ))
Return true;
}
# Endregion
}
// The simple password is definitely not included when you run it here
Return false;
}