Пример #1
0
        public void truncatedHashTest()
        {
            string userString = "test_password";
            string goodHash   = creator.CreateHash(userString);
            string badHash    = "";

            int badHashLength = goodHash.Length;

            do
            {
                badHashLength -= 1;
                badHash        = goodHash.Substring(0, badHashLength);
                bool raised = false;
                try
                {
                    creator.VerifyPassword(userString, badHash);
                }
                catch (InvalidHashException)
                {
                    raised = true;
                }

                if (!raised)
                {
                    Console.WriteLine("Truncated hash test: FAIL " +
                                      "(At hash length of " + badHashLength + ")");
                    System.Environment.Exit(1);
                }

                // The loop goes on until it is two characters away from the last : it
                // finds. This is because the PBKDF2 function requires a hash that's at
                // least 2 characters long. This will be changed once exceptions are
                // implemented.
            } while (badHash[badHashLength - 3] != ':');

            Console.WriteLine("Truncated hash test: pass");
        }