示例#1
0
        public static SplittedHash Parse(string str)
        {
            var sh = new SplittedHash();

            var ret = str.Split(new char[] { '$' }, 4, StringSplitOptions.RemoveEmptyEntries);

            if (ret.Length < 3)
            {
                throw new ArgumentException("Invalid MCF string");
            }

            sh.Protocol = ret[0];

            if (!ret[1].StartsWith("rounds="))
            {
                sh.Salt = ret[1];
                sh.Hash = ret[2];
            }
            else
            {
                sh.Rounds = ret[1];
                sh.Salt   = ret[2];
                sh.Hash   = ret[3];
            }

            return(sh);
        }
示例#2
0
        public static bool Verify(string hash, string password)
        {
            var    sh   = SplittedHash.Parse(hash);
            string salt = sh.GetFullSalt();

            // Has the password with the salt from the hash
            string newHash = Crypt(password, salt);

            return(hash == newHash);
        }