Пример #1
0
        private bool DoLogin()
        {
            _logger.Debug("Login");

            LoadHomePageWithCsrf();

            _engine.Evaluate(string.Format("var name = '{0}';", _config.Login));
            _engine.Evaluate(string.Format("var password = '******';", _config.Password));
            _engine.Evaluate(string.Format("var g_password_type = '4';"));

            var jsResult =
                _engine.Evaluate(
                    "psd = base64encode(SHA256(name + base64encode(SHA256(password)) + g_requestVerificationToken[0]));");

            //_engine.Evaluate("console.log(psd);");

            var requestJs = @"
var request = {
Username: name,
Password: psd,
password_type: g_password_type
};
var xmlDate = object2xml('request', request);";

            _engine.Evaluate(requestJs);

            // Show the xmlDate in console
            //_engine.Evaluate("console.log(xmlDate);");


            //var rsaData = engine.Evaluate("doRSAEncrypt(xmlDate)");
            var rsaData = _engine.Evaluate("xmlDate");



            /*
             * encstring = base64_encode(encstring);
             * var num = encstring.length / 245;
             * var restotal = '';
             * for (i = 0; i < num; i++) {
             * var encdata = encstring.substr(i * 245, 245);
             * var res = rsa.encrypt(encdata);
             * restotal += res;
             * }
             * return restotal;
             *
             */

            // Get the RSA encryption for login
            var data     = EncodeData(rsaData.ToString());
            var postData = new PostData(data)
                           .AddHeader("__RequestVerificationToken", _firstCsrf)
                           .AddHeader("encrypt_transmit", "encrypt_transmit");

            var postResult = _website.PostPage(_loginPageUrl, postData);

            if (postResult.Contains("OK"))
            {
                _logger.Debug("Login... Done!");
                return(true);
            }

            var errorMessage = ProcessErrorMessages(postResult);

            _logger.Error("Logging in failed: {0}", errorMessage);

            return(false);
        }