/// <summary>
    /// 判断是否是简单密码,不能包含相同的字符(如aaa,111),递增序列(abc,123),递减序列(cda,321)
    /// </summary>
    /// <param name="strPassword">密码</param>
    /// <param name="intTimes">相同字符或递增递减字符的个数</param>
    /// <returns></returns>
    private static bool HaveSimpleCode(string strPassword, int intTimes)
    {
        #region === 基本参数 ===

        System.Collections.ArrayList arrChar = new System.Collections.ArrayList();
        string strChar = "";
        string strTempA = "";
        string strTempB = "";
        string strTempSameChar = "";

        #endregion

        // 遍历所有字符
        for (int i = 0; i < strPassword.Length; i++)
        {
            #region === 避免重复访问多次 ===

            strChar = strPassword.Substring(i, 1);
            // 避免重复访问多次
            if (!arrChar.Contains(strChar))
            {
                arrChar.Add(strChar);
            }
            else
            {
                continue;
            }

            #endregion

            #region === 多次相同字符 ===
            strTempSameChar = "";
            // 多次相同字符
            for (int k = 0; k < intTimes; k++)
            {
                strTempSameChar = strTempSameChar + strChar;
            }

            // 若包含多个相同字符,则返回
            if (strPassword.Contains(strTempSameChar))
            {
                return true;
            }

            #endregion

            #region === 是否拥有递增或递减的序列 ===

            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;
                // 执行intTimes次,构建 ABC或CBA,123或321 字符串
                while (k < intTimes)
                {
                    byte[] byteArray = new byte[] { (byte)(intAsciiCode + k) };

                    string strCharacter = asciiEncoding.GetString(byteArray);

                    strTempA = strTempA + strCharacter;

                    strTempB = strCharacter + strTempB;

                    k++;
                }
                // 判断是否拥有递增或递减的序列
                if (strPassword.Contains(strTempA) || strPassword.Contains(strTempB))
                    return true;
            }
            #endregion
        }
        // 运行到此,肯定不包含简单密码了
        return false;
    }

posted on 2009-04-21 18:07  北极々冰雪  阅读(861)  评论(0编辑  收藏  举报