Beispiel #1
0
        public static string Hash(string password, HashScheme scheme)
        {
            switch (scheme)
            {
                case HashScheme.Plaintext:
                    return password;

                default:
                case HashScheme.SHA1:
                    return SHAHasher_5xN.Hash(password);
            }
        }
Beispiel #2
0
        public static string Hash(string password, HashScheme scheme)
        {
            switch (scheme)
            {
            case HashScheme.Plaintext:
                return(password);

            default:
            case HashScheme.SHA1:
                return(SHAHasher_5xN.Hash(password));
            }
        }
Beispiel #3
0
        private string ShortenDirect(string url)
        {
            string key;

            if (Repository.ContainsValue(url))
            {
                key = Repository.GetKey(url);
            }
            else
            {
                key = HashScheme.GetKey(url);
                int permutation = 0;
                while (Repository.ContainsKey(key))
                {
                    if (permutation == MaximumHashAttempts)
                    {
                        throw new Exception(String.Format("Failed to find a unique hash for url <{0}> after {1} attempts", url, permutation));
                    }
                    key = HashScheme.GetKey(url, ++permutation);
                }
                Repository.Add(key, url);
            }
            return(CompleteUrl(key));
        }
Beispiel #4
0
 public static bool Verify(string password, string hash, HashScheme scheme)
 {
     return hash == Hash(password, scheme);
 }
Beispiel #5
0
 public static bool Verify(string password, string hash, HashScheme scheme)
 {
     return(hash == Hash(password, scheme));
 }