判断是否是简单密码,不能包含相同的字符(如aaa,111),递增序列(abc,123),递减序列(cda,321)...

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

转载于:https://www.cnblogs.com/kklt2002/archive/2009/04/21/1440683.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值