Beispiel #1
0
        /// <summary>
        /// Returns a SaltPair containing the generated salt and the hashed salted password.
        /// Uses a SHA512 hasher for hashing operations
        /// </summary>
        /// <param name="shaker"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static SaltPair Hash(SaltShaker shaker, string password)
        {
            SaltPair embedded = shaker.Salt(password);

            if (hasher == null)
            {
                hasher = SHA512.Create();
            }

            byte[] data = Encoding.UTF8.GetBytes(embedded.SaltedPayload);
            data = hasher.ComputeHash(data);
            return(new SaltPair(embedded.Salt, new string(Encoding.UTF8.GetChars(data))));
        }
Beispiel #2
0
        /// <summary>
        /// Performs a salt/hash/compare of a cleartext password against a stored password hash using the provided shaker for salting.
        /// This assumes that the salting is properly specified in the shaker and expects that the salting is repeatable. And unrepeatable salt will always fail the compare, in this case the salt used for the storedcredential must also be passed.
        /// </summary>
        /// <param name="shaker"></param>
        /// <param name="password"></param>
        /// <param name="storedCredential"></param>
        /// <returns></returns>
        public static bool Matches(SaltShaker shaker, string password, string storedCredential)
        {
            SaltPair cur = Hash(shaker, password);

            return(cur.SaltedPayload.Equals(storedCredential));
        }