Example #1
0
        private string AddDeficientsFromDescriptor(string password, PasswordDescriptor descriptor)
        {
            var lockedIndices = new List <int>();

            if (descriptor.LowerCase)
            {
                password = AddDeficientIfNessesary(password, descriptor.Alphabet.LowerCase, lockedIndices);
            }

            if (descriptor.UpperCase)
            {
                password = AddDeficientIfNessesary(password, descriptor.Alphabet.UpperCase, lockedIndices);
            }

            if (descriptor.Digits)
            {
                password = AddDeficientIfNessesary(password, descriptor.Alphabet.Digits, lockedIndices);
            }

            if (descriptor.SpecialSymbols)
            {
                password = AddDeficientIfNessesary(password, descriptor.Alphabet.SpecialSymbols, lockedIndices);
            }

            return(password);
        }
Example #2
0
        public PasswordGenerator(string key, IHashCryptographer cryptographer = null, PasswordDescriptor descriptor = null, CoderBase coder = null)
        {
            PasswordDescriptor = descriptor;

            _key = key;

            _cryptographer = cryptographer ?? new PCLCryptographer();

            _coder = coder ?? new Coder();
        }
Example #3
0
        public string Generate(string input, PasswordDescriptor descriptor)
        {
            if (string.IsNullOrWhiteSpace(input))
            {
                throw new ArgumentException("input");
            }

            string forEncrypt = _key + input;

            string password = GeneratePasswordForDescriptor(forEncrypt, descriptor);

            return(password);
        }
Example #4
0
        private string GeneratePasswordForDescriptor(string input, PasswordDescriptor descriptor)
        {
            string password = _coder.ConvertBytesToString(_cryptographer.Encrypt(ConvertStringToBytes(input)), descriptor.GetCharArray());

            while (password.Length < descriptor.PasswordLength)
            {
                password += _coder.ConvertBytesToString(_cryptographer.Encrypt(ConvertStringToBytes(password)), descriptor.GetCharArray());
            }

            if (password.Length > descriptor.PasswordLength)
            {
                password = password.Substring(0, descriptor.PasswordLength);
            }

            password = AddDeficientsFromDescriptor(password, descriptor);

            return(password);
        }