Beispiel #1
0
        public string Compute(string password)
        {
            byte[] salt = GenerateSalt(_saltSize);

            HashedPassword hashedPassword = Compute(password, salt, _complexity, _algorithm);

            return((string)hashedPassword);
        }
Beispiel #2
0
        public bool Compare(string password, string hash)
        {
            bool matches = true;

            HashedPassword target = (HashedPassword)hash;
            HashedPassword source = Compute(password, target.Salt, target.Complexity, target.Algorithm);

            for (int i = 0; i < target.Content.Length; i++)
            {
                matches = matches && target.Content[i] == source.Content[i];
            }

            return(matches);
        }
Beispiel #3
0
        private HashedPassword Compute(string password, byte[] salt, byte complexity, ALGORITHM algorithm)
        {
            if (string.IsNullOrWhiteSpace(password))
            {
                throw new ArgumentNullException("Plain text password cannot be null, empty or whitespace");
            }

            HashedPassword hashedPassword = new HashedPassword(salt, complexity, algorithm);

            using (DeriveBytes provider = GetHashingProvider(password,
                                                             hashedPassword.Salt, hashedPassword.Iterations, hashedPassword.Algorithm))
            {
                hashedPassword.Content = provider.GetBytes(hashedPassword.Content.Length);
            }

            return(hashedPassword);
        }