Passwords are a very special type of string. When you type your password into an input box, a • appears instead of the letter you typed. They’ll often contain characters that are really hard to type (like the ~ symbol), and when they get put into a database they’re sometimes encrypted with some sort of “hash”. Plus, passwords can even get too old and expire.

Indeed, strings that are this special need special handling. At least, that’s what Pavel’s colleague must have been thinking when he developed this method and included into the company's common code library.

public static bool passwordsMatch(string pass1, string pass2)
{

    byte[] psswd1 = Encoding.Unicode.GetBytes(pass1);
    byte[] psswd2 = Encoding.Unicode.GetBytes(pass2);
    try
    {

        for (int i = 0; i < psswd1.Length; i++)
        {
            if (psswd1[i] != psswd2[i])
                return false;
        }
        return true;
    }
    catch (IndexOutOfRangeException)
    {
        return false;
    }

}