public static HashedAndSaltedPassword CryptPassword(string password, String defaultSalt = null)
        {
            var data = Encoding.UTF8.GetBytes(password);

            byte[] salt = null;
            if (defaultSalt == null)
            {
                salt = GenerateSalt();
            }
            else
            {
                SoapHexBinary hexBinary = SoapHexBinary.Parse(defaultSalt);
                salt = hexBinary.Value;
            }
            var saltedpass = Combine(data, salt);
            HashedAndSaltedPassword hashedAndSaltedPassword = new HashedAndSaltedPassword();

            using (SHA512 shaM = new SHA512Managed())
            {
                var           hash    = shaM.ComputeHash(saltedpass);
                SoapHexBinary crypted = new SoapHexBinary(hash);
                SoapHexBinary salted  = new SoapHexBinary(salt);
                hashedAndSaltedPassword.PasswordHash = crypted.ToString();
                hashedAndSaltedPassword.PasswordSalt = salted.ToString();
            }
            return(hashedAndSaltedPassword);
        }
        public static bool PasswordCompare(HashedAndSaltedPassword encryptedPassword, string plainPassword)
        {
            HashedAndSaltedPassword plainEncrypted = CryptPassword(plainPassword, encryptedPassword.PasswordSalt);
            SoapHexBinary           left           = SoapHexBinary.Parse(encryptedPassword.PasswordHash);
            SoapHexBinary           right          = SoapHexBinary.Parse(plainEncrypted.PasswordHash);

            return(SlowEquals(left.Value, right.Value));
        }