예제 #1
0
 /// <summary>
 /// Generate a random token or verification code.
 /// </summary>
 /// <param name="length">The exact length of the token.</param>
 /// <returns>The radom token generated.</returns>
 protected string GenerateToken(int length = 30)
 {
     // Create a new token.
     Nequeo.Invention.TokenGenerator token = new Invention.TokenGenerator();
     return(token.Random(length));
 }
예제 #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();
            }
        }
예제 #3
0
 /// <summary>
 /// Genrate a new nonce.
 /// </summary>
 /// <param name="size">The size of the nonce.</param>
 /// <returns>The nonce data.</returns>
 public string GenerateNonce(int size = 30)
 {
     Nequeo.Invention.TokenGenerator token = new Invention.TokenGenerator();
     return(token.Random(size));
 }