Beispiel #1
0
 ///<summary>Creates an encoded password string for storing in the database.  For use independent from the PasswordContainer struct.</summary>
 private static string EncodePass(HashTypes hashType, string passHash, string salt)
 {
     //No need to check RemotingRole; no call to db.
     return(string.Join("$", new string[] { hashType.ToString(), salt, passHash }));
 }
Beispiel #2
0
        private async Task FillMissingHashes(SVR_VideoLocal vlocal, CancellationToken token, IProgress <ICommand> progress = null)
        {
            HashTypes types = 0;

            if (string.IsNullOrEmpty(vlocal.CRC32))
            {
                types |= HashTypes.CRC;
            }
            if (string.IsNullOrEmpty(vlocal.MD5))
            {
                types |= HashTypes.MD5;
            }
            if (string.IsNullOrEmpty(vlocal.SHA1))
            {
                types |= HashTypes.SHA1;
            }
            if (types > 0)
            {
                FillVideoHashes(vlocal);
            }
            types = 0;
            if (string.IsNullOrEmpty(vlocal.CRC32))
            {
                types |= HashTypes.CRC;
            }
            if (string.IsNullOrEmpty(vlocal.MD5))
            {
                types |= HashTypes.MD5;
            }
            if (string.IsNullOrEmpty(vlocal.SHA1))
            {
                types |= HashTypes.SHA1;
            }
            if (types > 0)
            {
                _hashingState = true;
                DateTime start = DateTime.Now;
                logger.Trace("Calculating missing {1} hashes for: {0}", File.FullName, types.ToString("F"));
                // update the VideoLocal record with the Hash, since cloud support we calculate everything
                Hasher h     = new Hasher(File, HashAll);
                string error = await h.RunAsync(new ChildProgress(20, 60, this, progress), token);

                TimeSpan ts = DateTime.Now - start;
                logger.Trace("Hashed file in {0:#0.0} seconds --- {1} ({2})", ts.TotalSeconds, File.FullName, Utils.FormatByteSize(vlocal.FileSize));
                if (error != null)
                {
                    logger.Error("Unable to add additional hashes missing {1} hashes for: {0} Error {2}", File.FullName, types.ToString("F"), error);
                }
                else
                {
                    if ((types & HashTypes.CRC) > 0)
                    {
                        vlocal.CRC32 = h.Result.GetHash(HashTypes.CRC);
                    }
                    if ((types & HashTypes.MD5) > 0)
                    {
                        vlocal.MD5 = h.Result.GetHash(HashTypes.MD5);
                    }
                    if ((types & HashTypes.SHA1) > 0)
                    {
                        vlocal.SHA1 = h.Result.GetHash(HashTypes.SHA1);
                    }
                    WebCacheAPI.Instance.AddHash(new List <WebCache_FileHash> {
                        vlocal.ToHashRequest()
                    });
                }
            }
        }
Beispiel #3
0
        ///<summary>Will return the hash of whatever is passed in, including empty strings.
        ///Throws an exception if a passed in hash type is not implimented.</summary>
        public static string GetHash(string inputPass, string salt, HashTypes type)
        {
            //No need to check RemotingRole; no call to db.
            //Switch based on hashtype passed in.
            switch (type)
            {
            case HashTypes.MD5:
                return(HashPasswordMD5(salt + inputPass, false));

            case HashTypes.MD5_ECW:
                return(HashPasswordMD5(inputPass, true));                       //Backwards no salt ASCII way. >:(

            case HashTypes.SHA3_512:
                return(HashPasswordSHA512(inputPass, salt));                         //512 bit hash (64 byte)

            case HashTypes.None:
                return(inputPass);
            }
            throw new ApplicationException(Lans.g("Authentication", "Hash Type not implimented:") + " " + type.ToString());
        }