public async void AddServiceAsync(ServiceInformation service)
        {
            Contract.Assert(service != null);

            var services = (await LoadServicesAsync()).Concat(new[] { service });
            SaveServicesAsync(services);
        }
        public async void AddServiceAsync(ServiceInformation service)
        {
            Contract.Assert(service != null);

            var services = (await LoadServicesAsync()).Concat(new[] { service });

            SaveServicesAsync(services);
        }
        public void GeneratedPasswordShouldNotBeEmpty()
        {
            var serviceInfo = new ServiceInformation(
                "testService",
                new PasswordRestriction(SymbolsType.LowcaseLatin));

            var password =
                ServicePasswordGenerator.GeneratePassword(serviceInfo, _userPassword);

            Assert.IsTrue(password.Length > 0);
        }
        public void SecondaryGeneratedPasswordShouldBeSame()
        {
            var serviceInfo = new ServiceInformation(
                "testService",
                new PasswordRestriction(SymbolsType.LowcaseLatin));

            var password =
                ServicePasswordGenerator.GeneratePassword(serviceInfo, _userPassword);
            var secondaryGenerated =
                ServicePasswordGenerator.GeneratePassword(serviceInfo, _userPassword);

            Assert.AreEqual(password, secondaryGenerated);
        }
        public void ResultPasswordWithOtherUserPasswordShouldNotBeSame()
        {
            var serviceInfo = new ServiceInformation(
                "testService",
                new PasswordRestriction(SymbolsType.LowcaseLatin));

            var password =
                ServicePasswordGenerator.GeneratePassword(serviceInfo, _userPassword);

            _userPassword = "******";
            var otherPassword =
                ServicePasswordGenerator.GeneratePassword(serviceInfo, _userPassword);

            Assert.AreNotEqual(password, otherPassword);
        }
        public void PasswordForOtherServiceShouldNotBeSame()
        {
            var firstService = new ServiceInformation(
                "testService",
                new PasswordRestriction(SymbolsType.LowcaseLatin));

            var password = ServicePasswordGenerator.GeneratePassword(
                firstService,
                _userPassword);

            var secondService = new ServiceInformation(
                "testService",
                new PasswordRestriction(SymbolsType.LowcaseLatin));

            var otherPassword = ServicePasswordGenerator.GeneratePassword(
                secondService,
                _userPassword);

            Assert.AreNotEqual(password, otherPassword);
        }
        public static string GeneratePassword(ServiceInformation service, string userPassword)
        {
            Contract.Assert(service != null);
            Contract.Assert(userPassword.Length > 0);

            var passwordBasedNumbers = GetPasswordBasedNumbers(service.UniqueToken, userPassword);

            var passwordLength =
                CalculatePasswordLength(
                    restriction: service.Restriction,
                    randomNumber: passwordBasedNumbers.First());

            var randomNumbers = GetRandomNumbersFromPasswordBasedNumbers(
                2 * passwordLength,
                passwordBasedNumbers.Skip(1).ToArray());

            var mandatoryPartNumbersCount = randomNumbers.Length / 2;
            var mandatoryPartNumbers      = randomNumbers.Take(mandatoryPartNumbersCount).ToArray();

            var mandatoryPart = GenerateMandatoryPart(
                service.Restriction.AcceptedTypes,
                mandatoryPartNumbers);

            var restPartNumbers = randomNumbers.Skip(mandatoryPartNumbersCount).ToArray();
            var restPart        = GenerateRestPart(
                service.Restriction.AcceptedTypes,
                restPartNumbers,
                passwordLength - mandatoryPart.Length);

            var resultPassword = mandatoryPart + restPart;

            Contract.Assume(resultPassword.Length >= service.Restriction.PasswordMinLength);
            Contract.Assume(resultPassword.Length <= service.Restriction.PasswordMaxLength);

            return(resultPassword);
        }
        public static string GeneratePassword(ServiceInformation service, string userPassword)
        {
            Contract.Assert(service != null);
            Contract.Assert(userPassword.Length > 0);

            var passwordBasedNumbers = GetPasswordBasedNumbers(service.UniqueToken, userPassword);

            var passwordLength =
                CalculatePasswordLength(
                    restriction: service.Restriction,
                    randomNumber: passwordBasedNumbers.First());

            var randomNumbers = GetRandomNumbersFromPasswordBasedNumbers(
                2 * passwordLength,
                passwordBasedNumbers.Skip(1).ToArray());

            var mandatoryPartNumbersCount = randomNumbers.Length / 2;
            var mandatoryPartNumbers = randomNumbers.Take(mandatoryPartNumbersCount).ToArray();

            var mandatoryPart = GenerateMandatoryPart(
                service.Restriction.AcceptedTypes,
                mandatoryPartNumbers);

            var restPartNumbers = randomNumbers.Skip(mandatoryPartNumbersCount).ToArray();
            var restPart = GenerateRestPart(
                service.Restriction.AcceptedTypes,
                restPartNumbers,
                passwordLength - mandatoryPart.Length);

            var resultPassword = mandatoryPart + restPart;

            Contract.Assume(resultPassword.Length >= service.Restriction.PasswordMinLength);
            Contract.Assume(resultPassword.Length <= service.Restriction.PasswordMaxLength);

            return resultPassword;
        }
 public void AddServiceAsync(ServiceInformation service)
 {
     _services.Add(service);
     ServicesUpdated();
 }
        public void PasswordShouldContainsDifferentSymbols()
        {
            var serviceWithLotSymbolTypes = new ServiceInformation(
                "testService",
                new PasswordRestriction(
                    SymbolsType.LowcaseLatin |
                    SymbolsType.UpcaseLatin |
                    SymbolsType.Digital));

            var password = ServicePasswordGenerator.GeneratePassword(
                serviceWithLotSymbolTypes,
                _userPassword);

            Assert.IsTrue(
                SymbolsType.LowcaseLatin.GetSymbols().Any(symbol => password.Contains(symbol)));
            Assert.IsTrue(
                SymbolsType.UpcaseLatin.GetSymbols().Any(symbol => password.Contains(symbol)));
            Assert.IsTrue(
                SymbolsType.Digital.GetSymbols().Any(symbol => password.Contains(symbol)));
        }
        public void PasswordWithEqualsMinAndMaxLengthShouldBeSameLength()
        {
            var serviceWithLotSymbolTypes = new ServiceInformation(
                "testService",
                new PasswordRestriction(
                    SymbolsType.LowcaseLatin |
                    SymbolsType.UpcaseLatin |
                    SymbolsType.Digital,
                    passwordMinLength: 5,
                    passwordMaxLength: 5));

            var password = ServicePasswordGenerator.GeneratePassword(
                serviceWithLotSymbolTypes,
                _userPassword);

            Assert.IsTrue(password.Length == 5);
        }
        public void LongPasswordShouldBeSuccessfulGenerated()
        {
            var serviceWithLotSymbolTypes = new ServiceInformation(
                "testService",
                new PasswordRestriction(
                    SymbolsType.LowcaseLatin |
                    SymbolsType.UpcaseLatin |
                    SymbolsType.Digital,
                    passwordMinLength: 2000,
                    passwordMaxLength: 3000));

            var password = ServicePasswordGenerator.GeneratePassword(
                serviceWithLotSymbolTypes,
                _userPassword);

            Assert.IsTrue(password.Length >= 2000);
            Assert.IsTrue(password.Length <= 3000);
        }
 public void AddServiceAsync(ServiceInformation service)
 {
     _services.Add(service);
     ServicesUpdated();
 }