Beispiel #1
0
        /// <summary>
        /// Gets the service URL after determining the appropriate server to connect to.
        /// </summary>
        /// <param name="type">The host type.</param>
        /// <param name="callback">The callback handler when a result is retured, a client web response.</param>
        public void GetServiceURL(string type, Action <string, string[]> callback)
        {
            // Get the list of service urls.
            GetServiceURLs(type, (responseURls, state) =>
            {
                string url    = null;
                string[] urls = responseURls;

                // Make sure data exists.
                if (urls != null)
                {
                    // If urls exist.
                    if (urls.Length > 0)
                    {
                        // Randomly select the service index.
                        Nequeo.Invention.NumberGenerator number = new Invention.NumberGenerator();
                        string random = number.Random(1, urls.Length);

                        // Return the url.
                        url = urls[Int32.Parse(random)];
                    }
                    else
                    {
                        url = null;
                    }
                }
                else
                {
                    url = null;
                }

                // Send the callback.
                if (callback != null)
                {
                    callback(url, urls);
                }
            });
        }
Beispiel #2
0
        /// <summary>
        /// Generate the password.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnPasswordGeneratorGen_Click(object sender, EventArgs e)
        {
            // Get the minumum and maximum values.
            int min = Int32.Parse(txtPasswordGeneratorMin.Text);
            int max = Int32.Parse(txtPasswordGeneratorMax.Text);

            // If the minumum is greater than the maximum
            if (min > max)
            {
                MessageBox.Show(this, "The minimum length must not be greater than the maximum length.", "Invalid Length",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                Invention.IRandomGenerator gen = null;
                string genValue = string.Empty;

                // Select the generation type.
                switch (_selection)
                {
                case 1:
                    gen = new Invention.PasswordStandardGenerator();
                    break;

                case 2:
                    gen = new Invention.LowerUpperCaseGenerator();
                    break;

                case 3:
                    gen = new Invention.NumberLowerCaseGenerator();
                    break;

                case 4:
                    gen = new Invention.NumberUpperCaseGenerator();
                    break;

                case 5:
                    gen = new Invention.LowerCaseGenerator();
                    break;

                case 6:
                    gen = new Invention.UpperCaseGenerator();
                    break;

                case 7:
                    gen = new Invention.NumberGenerator();
                    break;

                case 8:
                    gen = new Invention.TokenGenerator();
                    break;

                case 9:
                    break;

                case 0:
                default:
                    gen = new Invention.PasswordGenerator();
                    break;
                }

                // Select the generation type.
                switch (_selection)
                {
                case 9:
                    genValue = Guid.NewGuid().ToString();
                    break;

                default:
                    genValue = gen.Random(min, max);
                    break;
                }

                // Generate the password.
                txtPasswordGeneratorGen.Text = genValue;

                // Get the password length score.
                int passwordLengthScore = 0;
                passwordStrengthLevel.Text = Invention.Validation.
                                             PasswordStrength(genValue, out passwordLengthScore).ToString().Replace('_', ' ') + ",  " +
                                             "Score = " + passwordLengthScore.ToString() + ",  Exellent > 100";

                // Calculate the entropy value.
                double bitRate    = 0.0;
                double metricRate = 0.0;
                double entropy    = Invention.Validation.EntropyShannon(genValue, out bitRate, out metricRate);
                lblEntropyValue.Text = entropy.ToString() + ",  Bit Rate = " + bitRate.ToString() + ",  Metric Rate = " + metricRate.ToString();

                // calculate the years taken to crak the password.
                double combinations = 1;
                double crackYears   = Invention.Validation.PasswordCrackTime(genValue, out combinations);

                string newNumber          = "";
                int    exponNotation      = 0;
                string metricPrefixName   = "";
                string metricPrefixSymbol = "";
                string name = Invention.Converter.GetNumberShortScaleName(crackYears, out newNumber, out exponNotation, out metricPrefixName, out metricPrefixSymbol);
                lblPasswordCrackTimeValue.Text = newNumber.Split('.')[0] + " " + metricPrefixSymbol + " (" + name + ") Years" + "   (" + crackYears + " Years)";
                txtPasswordCombinations.Text   = combinations.ToString();
            }
        }