It should implement Bot-API Login

Help
HayateYuki
2010-08-01
2013-05-13
  • HayateYuki
    HayateYuki
    2010-08-01

    Sometime, when the login page changed, like Wikia, the normal way seems to be broken…

            public void LogInEx()
            {
            string LoginData = string.Format("lgname={0}&lgpassword={1}",
                    HttpUtility.UrlEncode(userName), HttpUtility.UrlEncode(userPass));
               
               string queryUri = site + indexPath + "api.php?action=query&" + LoginData;
              string xmlSrc = PostDataAndGetResultHTM(queryUri, "action=login&" + LoginData);
              XmlDocument doc = new XmlDocument();
            doc.LoadXml(xmlSrc);
            if (doc.GetElementsByTagName("login").Count == 0) {
                    throw new WikiBotException("\n\n" + Bot.Msg("Login failed. Check your username and password.") + "\n");
            }
               string loginToken = doc.GetElementsByTagName("login")[0].Attributes["token"].Value;
               
            LoginData = string.Format("lgname={0}&lgpassword={1}&lgtoken={2}",
                    HttpUtility.UrlEncode(userName), HttpUtility.UrlEncode(userPass),
                    HttpUtility.UrlEncode(loginToken));
            queryUri = site + indexPath + "api.php?action=query&" + LoginData;
            xmlSrc = PostDataAndGetResultHTM(queryUri, "action=login&" + LoginData);
            doc.LoadXml(xmlSrc);
            if (doc.GetElementsByTagName("login").Count == 0) {
                throw new WikiBotException("\n\n" + Bot.Msg("Login failed. Check your username and password.") + "\n");
            }
            if (Regex.IsMatch(doc.GetElementsByTagName("login")[0].Attributes["result"].Value,"Success")){
                Console.WriteLine(Bot.Msg("Logged in as {0}."), userName);
                }
            }