예제 #1
0
        public void Generate(IGeneratorSettings generatorSettings)
        {
            if (String.IsNullOrWhiteSpace(this.txtPassword.Text))
            {
                MessageBox.Show(base.ParentForm,
                                "Provide a source password to be processed.", "Warning",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            IEntropyCalculator  entropyCalculator  = CalculatorFactory.Create <IEntropyCalculator>();
            IStrengthCalculator strengthCalculator = CalculatorFactory.Create <IStrengthCalculator>();
            ISecurityCalculator securityCalculator = CalculatorFactory.Create <ISecurityCalculator>();

            String   password = this.txtPassword.Text;
            Double   entropy  = entropyCalculator.Calculate(password);
            Strength strength = strengthCalculator.Calculate(entropy);
            Scenario scenario = this.cmbScenario.SelectedValue as Scenario;

            // Don't change this order.
            this.cntEntropy.Strength = strength;
            this.cntEntropy.Entropy  = entropy;
            this.cntEntropy.Percent  = strengthCalculator.ToPercent(entropy);
            this.cntEntropy.Summary  = strengthCalculator.ToSummary(strength);

            if (entropy > 0d)
            {
                Duration duration = securityCalculator.Calculate(scenario, entropy);
                this.cntDuration.SetDuration(duration);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="T:Core.PasswordGeneratorBase"/> class.
 /// </summary>
 protected PasswordGeneratorBase(IRandomNumberGenerator randomNumberGenerator, IStrengthCalculator strengthCalculator)
 {
     if (randomNumberGenerator == null)
     {
         throw new ArgumentNullException("randomNumberGenerator");
     }
     if (strengthCalculator == null)
     {
         throw new ArgumentNullException("strengthCalculator");
     }
     _rng = randomNumberGenerator;
     _sc  = strengthCalculator;
 }
예제 #3
0
        public ExtendedGeneratorControl()
            : base()
        {
            this.InitializeComponent();
            this.lstPasswords.Items.Clear();

            this.entropyCalculator  = CalculatorFactory.Create <IEntropyCalculator>();
            this.strengthCalculator = CalculatorFactory.Create <IStrengthCalculator>();

            StandardContextMenu contextMenu = StandardContextMenu.Create(this.OnContextMenuItemClick);

            contextMenu.Opening += this.OnContextMenuOpening;

            this.numLength.ContextMenuStrip    = contextMenu;
            this.numAmount.ContextMenuStrip    = contextMenu;
            this.lstPasswords.ContextMenuStrip = contextMenu;
        }
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        /// <filterpriority>2</filterpriority>
        public virtual void Dispose()
        {
            if (_disposed)
            {
                return;
            }

            if (_rng != null)
            {
                _rng.Dispose();
            }
            _rng = null;

            if (_sc != null && _sc is IDisposable)
            {
                ((IDisposable)_sc).Dispose();
            }
            _sc = null;

            _disposed = true;
            GC.SuppressFinalize(this);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="T:Core.DefaultPasswordGenerator"/> class.
 /// </summary>
 public DefaultPasswordGenerator(IRandomNumberGenerator randomNumberGenerator, IStrengthCalculator strengthCalculator) : base(randomNumberGenerator, strengthCalculator)
 {
 }