Beispiel #1
0
    private static void testCSharpHashes()
    {
        string userPW   = "test_password";
        string goodHash = PasswordStorage.CreateHash(userPW);

        // Good password.
        string            args = "tests/phpVerify.php" + " " + userPW + " " + goodHash;
        CommandExecResult goodHashExecution = RunCommand("php", args);

        if (goodHashExecution.exitCode == 0)
        {
            Console.WriteLine("C# hash valdating in PHP: pass");
        }
        else if (goodHashExecution.exitCode == 1)
        {
            Console.WriteLine("C# hash validating in PHP: FAIL");
            System.Environment.Exit(1);
        }

        // Bad password.
        args = "tests/phpVerify.php" + " " + "wrongPassword" + " " + goodHash;
        CommandExecResult badHashExecution = RunCommand("php", args);

        if (badHashExecution.exitCode == 0)
        {
            Console.WriteLine("C# hash validating wrong password in PHP: FAIL");
            System.Environment.Exit(1);
        }
        else if (badHashExecution.exitCode == 1)
        {
            Console.WriteLine("C# hash validating wrong password in PHP: pass");
        }
    }
Beispiel #2
0
    private static void testPHPHashes()
    {
        string[] testData     = null;
        char[]   useDelimiter = { ' ' };

        // Good password.
        CommandExecResult goodHashExecution = RunCommand("php", "tests/phpHashMaker.php");

        testData = goodHashExecution.stdOut.Split(useDelimiter);

        if (testData[1].Length != Int32.Parse(testData[0]))
        {
            Console.WriteLine("Unicode test is invalid.");
            System.Environment.Exit(1);
        }

        if (PasswordStorage.VerifyPassword(testData[1], testData[2]))
        {
            Console.WriteLine("PHP hash validating in C#: pass");
        }
        else
        {
            Console.WriteLine("PHP hash validating in C#: FAIL");
            System.Environment.Exit(1);
        }

        // Bad password.
        CommandExecResult badHashExecution = RunCommand("php", "tests/phpHashMaker.php");

        testData = badHashExecution.stdOut.Split(useDelimiter);

        if (testData[1].Length != Int32.Parse(testData[0]))
        {
            Console.WriteLine("Unicode test is invalid.");
            System.Environment.Exit(1);
        }

        if (PasswordStorage.VerifyPassword("wrongPassword", testData[2]))
        {
            Console.WriteLine("The C# implementation accepts BAD PHP hashes: FAIL");
            System.Environment.Exit(1);
        }
        else
        {
            Console.WriteLine("The C# implementation will not accept bad PHP hashes: pass");
        }
    }