Exemplo n.º 1
0
        public bool Login(string username, string password, int attempNo = 0)
        {
            const string url = "https://auctions.godaddy.com";
            var responseData = Get(url);
            var key = GetSubString(responseData, "spkey=", "&");

            var loginUrl = string.Format("https://idp.godaddy.com/login.aspx?SPKey={0}", key);
            var hdoc = HtmlDocument(Get(loginUrl));
            if (QuerySelector(hdoc.DocumentNode, "img[class='LBD_CaptchaImage']") != null)
            {
                //Solve Captcha

                var captchaId =
                     QuerySelector(hdoc.DocumentNode, "input[id='LBD_VCID_idpCatpcha']").Attributes["value"]
                         .Value;
                var imagedata =
                    GetImage(QuerySelector(hdoc.DocumentNode, "img[class='LBD_CaptchaImage']").Attributes["src"].Value);

                try
                {
                    imagedata.Save(Path.Combine(Path.GetTempPath(), username + ".jpg"), ImageFormat.Jpeg);
                    Client client;
                    using (var ds = new ASEntities())
                    {
                        var user = ds.SystemConfig.First(x => x.PropertyID == "DBCUser").Value;
                        var pass = ds.SystemConfig.First(x => x.PropertyID == "DBCPass").Value;
                        client = new SocketClient(user, pass);
                    }

                    //var balance = client.GetBalance();
                    var captcha = client.Decode(Path.Combine(Path.GetTempPath(), username+".jpg"), 20);
                    if (null != captcha)
                    {
                        /* The CAPTCHA was solved; captcha.Id property holds its numeric ID,
                           and captcha.Text holds its text. */
                        Console.WriteLine(@"CAPTCHA {0} solved: {1}", captcha.Id, captcha.Text);
                        var capturetext = captcha.Text;

                        var view = ExtractViewStateSearch(hdoc.DocumentNode.InnerHtml);
                        //var view = QuerySelector(hdoc.DocumentNode, "input[id='__VIEWSTATE'") == null ? "" :
                        //QuerySelector(hdoc.DocumentNode, "input[id='__VIEWSTATE'").Attributes["value"].Value;
                        var postData = string.Format("__VIEWSTATE={0}&Login%24userEntryPanel2%24UsernameTextBox={1}&Login%24userEntryPanel2%24PasswordTextBox={2}&captcha_value={3}&LBD_VCID_idpCatpcha={4}&Login%24userEntryPanel2%24LoginImageButton.x=0&Login%24userEntryPanel2%24LoginImageButton.y=0",
                            view, username, password, capturetext, captchaId);

                        responseData = Post(loginUrl, postData);

                        if (!responseData.Contains("sessionTimeout_onLogout"))
                        {
                            client.Report(captcha);
                        }

                        return responseData.Contains("sessionTimeout_onLogout");
                    }
                }
                catch(Exception e)
                {
                    new Error().Add(e.Message);
                    //Email.SendEmail(AppConfig.GetSystemConfig("AlertEmail"),"Captcha Failure",e.Message);
                    CaptchaOverload = true;
                }
            }
            else
            {
                var postData = string.Format("loginName={0}&password={1}", username, password);

                responseData = Post(loginUrl, postData);

                return responseData.Contains("sessionTimeout_onLogout");
            }

            if (attempNo < 3)
            {
                Login(username, password, attempNo++);
            }

            return false;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Login to godaddy auctions
        /// </summary>
        /// <returns></returns>
        public bool Login(int attempNo = 0)
        {
            const string url = "https://auctions.godaddy.com/";
            var responseData = Get(url);
            //Skip if we are logged in
            if (LoggedIn(responseData))
            {
                return true;
            }
            var key = GetSubString(responseData, "spkey=", "\"");
            var loginurl = string.Format("https://idp.godaddy.com/login.aspx?SPKey={0}", key);
            var hdoc = HtmlDocument(Get(loginurl));
            if (QuerySelector(hdoc.DocumentNode, "img[class='LBD_CaptchaImage']") != null)
            {
                //Solve Captcha
                var captchaId =
                    QuerySelector(hdoc.DocumentNode, "input[id='LBD_VCID_idpCatpcha']").Attributes["value"]
                        .Value;
                var imagedata =
                    GetImage(QuerySelector(hdoc.DocumentNode, "img[class='LBD_CaptchaImage']").Attributes["src"].Value);


                try
                {
                    imagedata.Save(Path.Combine(Path.GetTempPath(), _sessionDetails.GoDaddyAccount.Username + ".jpg"), ImageFormat.Jpeg);
                    Client client;
                    var user = _sessionDetails.DeathByCapture.Username;
                    var pass = _sessionDetails.DeathByCapture.Password;
                    client = new SocketClient(user, pass);

                    //var balance = client.GetBalance();
                    var captcha = client.Decode(Path.Combine(Path.GetTempPath(), _sessionDetails.GoDaddyAccount.Username + ".jpg"), 20);
                    if (null != captcha)
                    {
                        /* The CAPTCHA was solved; captcha.Id property holds its numeric ID,
                           and captcha.Text holds its text. */
                        Console.WriteLine(@"CAPTCHA {0} solved: {1}", captcha.Id, captcha.Text);
                        var capturetext = captcha.Text;

                        var view = ExtractViewStateSearch(hdoc.DocumentNode.InnerHtml);
                        //var view = QuerySelector(hdoc.DocumentNode, "input[id='__VIEWSTATE'") == null ? "" :
                        //QuerySelector(hdoc.DocumentNode, "input[id='__VIEWSTATE'").Attributes["value"].Value;
                        var postData =
                            string.Format(
                                "__VIEWSTATE={0}&Login%24userEntryPanel2%24UsernameTextBox={1}&Login%24userEntryPanel2%24PasswordTextBox={2}&captcha_value={3}&LBD_VCID_idpCatpcha={4}&Login%24userEntryPanel2%24LoginImageButton.x=0&Login%24userEntryPanel2%24LoginImageButton.y=0",
                                view, _sessionDetails.GoDaddyAccount.Username, _sessionDetails.GoDaddyAccount.Password, capturetext, captchaId);

                        responseData = Post(loginurl, postData);

                        if (!responseData.Contains("sessionTimeout_onLogout"))
                        {
                            client.Report(captcha);
                        }

                        return responseData.Contains("sessionTimeout_onLogout");
                    }
                }
                catch (Exception e)
                {
                    UserRepository.LogError(e.Message);
                    CaptchaOverload = true;
                }
            }
            else
            {
                var secondaryLogin = string.Format("https://sso.godaddy.com/?app=idp&path=%2flogin.aspx%3fSPKey%3d{0}", key);

                var loginData = string.Format("loginName={0}&password={1}",
                    Uri.EscapeDataString(_sessionDetails.GoDaddyAccount.Username),
                    Uri.EscapeDataString(_sessionDetails.GoDaddyAccount.Password));
                var firstLoginResponse = Post(loginurl, loginData);
                var login2Data = string.Format("name={0}&password={1}",
                    Uri.EscapeDataString(_sessionDetails.GoDaddyAccount.Username),
                    Uri.EscapeDataString(_sessionDetails.GoDaddyAccount.Password));

                var secondaryLoginResponse = Post(secondaryLogin, login2Data);

                return LoggedIn(secondaryLoginResponse);
            }

            if (attempNo < 3)
            {
                Login(attempNo++);
            }

            return false;
        }