Untitled

 avatar
user_2299906
plain_text
2 years ago
7.2 kB
5
Indexable
 public Task LoginFacebook(bool IsClosed = true)
        {
            return Task.Run(() =>
            {
                try
                {
                    Random rd = new Random(Guid.NewGuid().GetHashCode());
                    string loginid = pro.UID;
                    int flagagain = 0;
                    again:;
                    driver.GoToUrl("https://m.facebook.com/");
                    Task.Delay(rd.Next(2000, 3000)).Wait();                    
                    string temp = driver.PageSource;
                    HtmlDocument doc = new HtmlDocument();
                    doc.LoadHtml(temp);
                    var tag = doc.DocumentNode.SelectSingleNode("//button[@name='login']");
                    if(tag != null)
                    {
                        if (string.IsNullOrEmpty(pro.Password))
                        {
                            pro.Status = "Không tìm thấy mật khẩu";
                            return;
                        }
                      
                        if (temp.Contains("m_login_email"))
                            driver.ExecuteScript($"document.getElementById('m_login_email').value = '{loginid}';");
                        else driver.ExecuteScript($"document.getElementsByName('email')[0].value = '{loginid}';");
                       Task.Delay(rd.Next(1000, 2000)).Wait();      
                        if (temp.Contains("m_login_password"))
                            driver.ExecuteScript($"document.getElementById('m_login_password').value = '{pro.Password}';");
                        else driver.ExecuteScript($"document.getElementsByName('pass')[0].value = '{pro.Password}';");
                       Task.Delay(rd.Next(1000, 2000)).Wait();      

                        driver.ExecuteScript("document.getElementsByName('login')[0].click();");
                        Task.Delay(rd.Next(3000, 4000)).Wait();      
                        temp = driver.PageSource;
                        if (temp.Contains("name=\"pass\"")|| temp.Contains("password_failure"))
                        {
                            pro.Status = "Sai UID|Pass";
                        }
                        else if(!temp.Contains(" id=\"approvals_code\" "))
                        {
                            if(!string.IsNullOrEmpty(pro.Email))
                            {
                                loginid = pro.Email;
                            }
                            flagagain++;
                            if(flagagain == 1)
                            goto again;

                        }    
                        else
                        {
                            int doi = 0;
                            while (string.IsNullOrEmpty(temp) || !temp.Contains(" id=\"approvals_code\" "))
                            {
                               Task.Delay(rd.Next(1000, 2000)).Wait();      
                                doi++;
                                if (doi > 15) break;
                                temp = driver.PageSource;
                            }
                            if (string.IsNullOrEmpty(temp) || !temp.Contains(" id=\"approvals_code\" "))
                            {
                                pro.Status = "Lỗi đăng nhập";
                            }
                            else
                            {
                                if (string.IsNullOrEmpty(pro.SecrectKey))
                                {
                                    pro.Status = "không tìm thấy 2fa";
                                }
                                else
                                {
                                    var tfa = new TwoFactorAuth(); string code = "";
                                    int lan = 1;
                                    quaylai:;
                                    while (string.IsNullOrEmpty(code))
                                    {
                                        code = tfa.GetCode(pro.SecrectKey.Replace(" ", "").ToUpper());
                                        lan++;
                                    }
                                    driver.ExecuteScript("document.getElementById('approvals_code').value = '" + code + "';");
                                   Task.Delay(rd.Next(1000, 2000)).Wait();      

                                    driver.ExecuteScript("document.getElementById('checkpointSubmitButton-actual-button').click();");
                                   Task.Delay(rd.Next(1000, 2000)).Wait();      
                                    string check = driver.PageSource;
                                    if (string.IsNullOrEmpty(check) || check.Contains(" id=\"approvals_code\" "))
                                    {
                                        code = "";
                                        lan++;
                                        if (lan < 5)
                                            goto quaylai;
                                    }
                                    string checklog = driver.PageSource;
                                    int clicksubmit = 0;
                                    while (!string.IsNullOrEmpty(checklog) && checklog.Contains("checkpointSubmitButton"))
                                    {
                                       Task.Delay(rd.Next(1000, 2000)).Wait();      
                                        driver.ExecuteScript("document.getElementById('checkpointSubmitButton-actual-button').click();");
                                        clicksubmit++;
                                        if (clicksubmit > 3) break;
                                        checklog = driver.PageSource;
                                    }
                                }

                            }
                        }
                    }                    
                    driver.GoToUrl("https://www.facebook.com/");
                    Task.Delay(rd.Next(1000, 2000)).Wait();      
                    var cookie = driver.Manage().Cookies.AllCookies.ToList();
                    string coo = "";
                    foreach (var cook in cookie)
                    {
                        try
                        {
                            if (cook.Domain.Equals(".facebook.com"))
                                coo += cook.Name + "=" + cook.Value + ";";
                        }
                        catch { }

                    }
                    if (Regex.IsMatch(coo, "c_user=(\\d+);"))
                    {
                        pro.Cookie = coo;
                        pro.Status = "Hoàn thành";
                    }
                    Task.Delay(2000).Wait();
                }
                catch
                {
                }
                try
                {
                    driver?.Close();
                    driver?.Dispose();
                } catch { }
            });

        }
Editor is loading...