Determine whether the password is a simple password. It cannot contain the same characters (such as aaa, 111), ascending sequence (abc, 123), and descending sequence (cda, 321)

Source: Internet
Author: User

/// <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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.