예제 #1
0
파일: Form1.cs 프로젝트: ec-jrc/jrcpastme
        private double evaluate_pwd(string pwd_to_evaluate, string output_path = "")
        {
            if (File.Exists(CFHMM_matrix_path) && File.Exists(SimpleHMM_matrix_path) && M.count() != 0)
            {
                string text_to_save = "";
                if (output_path == "")
                {
                    if (checkBox_hiddenpwd.Checked)
                    {
                        //the password should be hidden, we don't display it
                        console_textbox.AppendText("\r\n[-] Evaluating the password: *hidden*\r\n");
                    }
                    else
                    {
                        console_textbox.AppendText("\r\n[-] Evaluating the password:\r\n     " + pwd_to_evaluate + "\r\n");
                    }
                }
                text_to_save += pwd_to_evaluate;

                if (output_path == "")
                {
                    console_textbox.AppendText("\r\n     * Test for LIST_strengthMetric");
                }

                double SlistInMain = PasswordStrength.LIST_strengthMetric(pwd_to_evaluate, FileOfBannedPasswords);
                if (output_path == "")
                {
                    console_textbox.AppendText("\r\n               -> Result: " + SlistInMain.ToString("0.###") + "\r\n");
                }
                text_to_save += ", " + SlistInMain.ToString();

                // TEST FOR BF_strengthMetric
                if (output_path == "")
                {
                    console_textbox.AppendText("\r\n     * Test for BF_strengthMetric");
                }

                double SbfInMain = PasswordStrength.BF_strengthMetric(pwd_to_evaluate, LminNum, LminLower, LminUpper, LminSpecial, LminTwo, LminThree, LminAll); // bool DebugOption

                if (output_path == "")
                {
                    console_textbox.AppendText("\r\n               -> Result: " + SbfInMain.ToString("0.###") + "\r\n");
                }
                text_to_save += ", " + SbfInMain.ToString();

                // TEST FOR MM_strengthMetric
                //PasswordStrength.MM_strengthMetric("total_matrix_mem3.mat");
                if (output_path == "")
                {
                    console_textbox.AppendText("\r\n     * Test for AMM_strengthMetric ");
                }
                double Sa = 0;
                if (ConfigurationManager.AppSettings["char_encoding"] == "0")
                {
                    Sa = PasswordStrength.MM_strengthMetric_Hashlist_Ascii(M, pwd_to_evaluate, MM_memsize);
                }
                else
                {
                    Sa = PasswordStrength.MM_strengthMetric_Hashlist_Uni1K(M, pwd_to_evaluate, MM_memsize);
                }
                double Sa_norm = -1.0;
                if (Sa != -1)
                {
                    if (double.IsInfinity(Sa))
                    {
                        Sa_norm = 10.0;
                    }
                    else
                    {
                        Sa_norm = 5.0 * Math.Tanh(0.01 * (Sa - 162.6786)) + 5.0;
                    }
                }
                if (output_path == "")
                {
                    //console_textbox.AppendText("  -> Sa: " + Sa.ToString());
                    console_textbox.AppendText("\r\n               -> Result: " + Sa_norm.ToString("0.###") + "\r\n");
                }

                //text_to_save += ", " + Sa.ToString();
                text_to_save += ", " + Sa_norm.ToString();

                // TEST FOR CFHMM_strengthMetric
                if (output_path == "")
                {
                    console_textbox.AppendText("\r\n     * Test for CFHMM_strengthMetric");
                }

                double Sn = PasswordStrength.CFHMM_strengthMetric_V2(pwd_to_evaluate, CFHMM_matrix_path);

                double Ss = 0;
                double Sn_norm;

                if (Sn == 0)
                {
                    Ss      = PasswordStrength.SimpleHMM_strengthMetric_V2(pwd_to_evaluate, SimpleHMM_matrix_path);
                    Sn_norm = 5.0 * Math.Tanh(0.01 * (Ss - 13.0325) / 0.15) + 5.0;
                }
                else
                {
                    Sn_norm = 5.0 * Math.Tanh(0.01 * (Sn - 13.4383) / 0.15) + 5.0;
                }

                if (output_path == "")
                {
                    //console_textbox.AppendText(" -> Sn: " + Sn.ToString());
                    console_textbox.AppendText("\r\n               -> Result: " + Sn_norm.ToString("0.###") + "\r\n");
                }
                //text_to_save += ", " + Sn.ToString();
                text_to_save += ", " + Sn_norm.ToString();

                if (output_path == "")
                {
                    console_textbox.AppendText("\r\n     * Fusion of the scores");
                }
                int    maximumLength = 40;
                double Smulti        = 10.0;
                if (pwd_to_evaluate.Length <= maximumLength)
                {
                    Smulti = PasswordStrength.FusionWS(SlistInMain, SbfInMain, Sa_norm, Sn_norm);
                    //Smulti = PasswordStrength.fusionWS(SlistInMain, SbfInMain, Sa_norm, Sn_norm);
                }

                if (Smulti < 0)
                {
                    Smulti = 0.2;
                }
                if (output_path == "")
                {
                    console_textbox.AppendText("\r\n            ************************");
                    console_textbox.AppendText("\r\n            ***** SCORE: " + Smulti.ToString("0.000") + " *****");
                    console_textbox.AppendText("\r\n            ************************");
                }
                text_to_save += ", " + Smulti.ToString() + "\n";


                //Write the result into the file if output_path is not empty
                //It should have been previously checked that output_path is a file
                //but just to be sure we check again here
                if (output_path != "")
                {
                    File.AppendAllText(output_path, text_to_save);
                }

                //we are returning the score, so far sa_norm as we do not have the fusion
                return(Smulti);
            }
            else
            {
                initialize_panel_buttons();
                panel_training.Visible         = true;
                button_training.Enabled        = false;
                button_training.BackColor      = System.Drawing.Color.FromArgb(255, 204, 0);
                button_training.ForeColor      = System.Drawing.Color.Black;
                checkbox_advanced_view.Checked = true;
                console_textbox.AppendText("\r\n [!] One of the matrix or the blacklist file is missing. Check if they are present in the " +
                                           "folder or consider re-training them.");
                return(0);
            }
        }