Beispiel #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        /**
         * 最开始的网页
         * 侦测admin被攻击的状态
         * 如果达到4级,直接打到攻击警告页面重置
         */

        Session["UsersID"] = 0;
        long lJudgementValue = 0L;

        AdminInfoBusiness AdminInfoBusiness = new AdminInfoBusiness();

        AdminInfoEntity ThreateningLevel = new AdminInfoEntity();

        ThreateningLevel = AdminInfoBusiness.GetAdminInfoByAdminAccount();
        lJudgementValue  = ThreateningLevel.iadminInfoHackedThreateningLevel;

        if (lJudgementValue != 4)
        {
            Response.Redirect("~/00Default.aspx");
        }
        else if (lJudgementValue == 4)
        {
            AttractedWarning AttractedWarningSolution4 = new Level4Warning();
            AttractedWarningSolution4.WarningMethod();
        }
    }
    public int SimilarityDetect(string sTargetString, string sStandbyString)
    {
        /**
         * 通过继承本方法,来实现【相似度检测】功能
         * 简单实现字符串相似度检测
         * 分为四个级别
         * 不同的相似度产生不同的解决方案,使用多态来完成
         */
        int iSolutionResult = 0;
        AttractedWarning AttractedWarningSolution1 = new Level1Warning();
        AttractedWarning AttractedWarningSolution2 = new Level2Warning();
        AttractedWarning AttractedWarningSolution3 = new Level3Warning();
        AttractedWarning AttractedWarningSolution4 = new Level4Warning();
        float            fCount = 0;
        int iMinStringLength    = sTargetString.Length < sStandbyString.Length ? sTargetString.Length : sStandbyString.Length;

        for (int i = 0; i < iMinStringLength; i++)
        {
            if (sTargetString[i] == sStandbyString[i])
            {
                fCount++;
            }
        }
        int   iMaxStringLength = sTargetString.Length > sStandbyString.Length ? sTargetString.Length : sStandbyString.Length;
        float iResult          = fCount / iMaxStringLength * 100;

        if (fCount / iMaxStringLength != 0)
        {
            if (iResult > 45 && iResult <= 55)
            {
                iSolutionResult = AttractedWarningSolution1.WarningMethod();
            }
            else if (iResult > 55 && iResult <= 75)
            {
                iSolutionResult = AttractedWarningSolution2.WarningMethod();
            }
            else if (iResult > 75 && iResult <= 85)
            {
                iSolutionResult = AttractedWarningSolution3.WarningMethod();
            }
            else if (iResult > 85 && iResult < 100)
            {
                iSolutionResult = AttractedWarningSolution4.WarningMethod();
            }
            else if (iResult == 100)
            {
                iSolutionResult = 100;
            }
        }
        else
        {
            iSolutionResult = 0;
        }

        return(iSolutionResult);
    }