예제 #1
0
        public async Task GeneratePasswordsAsync()
        {
            if (this.passwordLength < 8 || this.passwordCount < 1 || this.usableCharacters.Distinct().Count() < 1)
            {
                return;
            }

            this.generateButtonIsEnabled = false;
            this.cancelButtonIsEnabled   = true;
            this.passwordGeneratedCount  = 0;
            this.progressMax             = this.passwordCount;
            this.completeIconVisible     = false;

            var generator = new RandomPassword(passwordLength, this.usableCharacters);

            if (this.useCharacterOver3Kinds && RandomPassword.CalculateCharacterKindCount(this.usableCharacters) >= 3)
            {
                generator = generator.CharacterShuoldHaveOverThreeKinds();
            }
            if (this.useUniqueCharacter && this.passwordLength < (this.usableCharacters.Length / 3))
            {
                generator = generator.CharacterShouldNotDuplicate();
            }
            if (this.notStartWithExcelSpecialCharacter && this.passwordLength > 1)
            {
                generator = generator.NotStartWithExcelSpecialCharacter();
            }
            this.passwordGeneratedCount = 0;
            string result = string.Empty;

            this.generatedPasswordList = string.Empty;
            string passwordList = string.Empty;

            this.generatingIsCanceled = false;

            await foreach (var passwordWithRuby in generator.GeneratePasswordAsync(this.passwordCount))
            {
                passwordList += passwordWithRuby.Password + "\t" + passwordWithRuby.Ruby + "\r\n";
                this.passwordGeneratedCount++;

                if (this.passwordGeneratedCount % 10 == 0)
                {
                    if (this.generatingIsCanceled)
                    {
                        this.generatingIsCanceled = false;
                        break;
                    }
                    StateHasChanged();
                    await Task.Delay(10);
                }
            }

            this.generatedPasswordList   = passwordList;
            this.completeIconVisible     = true;
            this.generateButtonIsEnabled = true;
            this.cancelButtonIsEnabled   = false;
        }
예제 #2
0
        public async Task Test1()
        {
            string usableChars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
            var    passGen     = new RandomPassword(32, usableChars);

            passGen = passGen.CharacterShuoldHaveOverThreeKinds();

            this.logger.WriteLine("Environment.OSVersion :" + Environment.OSVersion.ToString());
            await foreach (var x in passGen.GeneratePasswordAsync(100))
            {
                this.logger.WriteLine(x.Password);
                Assert.Equal(32, x.Password.Length);
            }
        }