public static bool minecraftLogin(string username, string password, ref string authToken, CookieContainer cookie)
{
    authToken = Regex.Split(getResponse("http://minecraft.net/login", cookie), "authenticityToken\" value=\"(.*?)\"")[1];
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://minecraft.net/login");
    request.Method = "POST";
    request.ContentType = "application/x-www-form-urlencoded";
    request.CookieContainer = cookie;

    StreamWriter sw = new StreamWriter(request.GetRequestStream());
    sw.Write("authenticityToken=" + authToken + "&redirect=https%3A%2F%2Fminecraft.net%2F&username=" + username + "&password=" + password);
    sw.Close();

    HttpWebResponse response = (HttpWebResponse)request.GetResponse();

    if (response.StatusCode == HttpStatusCode.OK)
    {
        Stream resStream = response.GetResponseStream();
        StreamReader readStream = new StreamReader(resStream, Encoding.Default);
        string result = readStream.ReadToEnd();

        resStream.Close();
        readStream.Close();
        if (result.IndexOf("Logged in as") > -1) return true;
    }
    return false;
}