public async Task <IActionResult> VerifyChallenge(string code)
        {
            code = code.Trim();
            code = code.Replace(" ", "");
            var regex = new Regex(@"^-*[0-9,\.]+$");

            if (!regex.IsMatch(code))
            {
                ViewData["ErrorMessage"] = "لطفا فقط عدد وارد نمایید";
                return(View());
            }
            if (code.Length != 6)
            {
                ViewData["ErrorMessage"] = "کد تاییدیه باید 6 رقم باشد";
                return(View());
            }
            var verify = await api.VerifyCodeForChallengeRequireAsync(code);

            if (verify.Succeeded)
            {
                string state = await api.GetStateDataAsStringAsync();

                await System.IO.File.WriteAllTextAsync(TextFileUrl, string.Empty);

                string[] lines = { user.UserName, user.Password, state };
                await System.IO.File.WriteAllLinesAsync(TextFileUrl, lines);

                return(RedirectToAction("Index", "Poll"));
            }
            else
            {
                if (verify.Value == InstaLoginResult.TwoFactorRequired)
                {
                    return(RedirectToAction("TwoFactor"));
                }
            }
            ViewData["ErrorMessage"] = verify.Info.Message;
            return(View());
        }
        public async Task <IActionResult> Index(string username, string password)
        {
            if (username == null || password == null)
            {
                ViewData["ErrorMessage"] = "هر دو فیلد باید پر شود";
                ViewData["Username"]     = username;
                ViewData["Password"]     = password;
                return(View());
            }

            user          = new UserSessionData();
            user.UserName = username;
            user.Password = password;
            api           = InstaApiBuilder.CreateBuilder()
                            .SetUser(user)
                            .UseLogger(new DebugLogger(LogLevel.Exceptions))
                            .Build();


            var result = await api.LoginAsync();

            if (result.Succeeded)
            {
                string state = await api.GetStateDataAsStringAsync();

                await System.IO.File.WriteAllTextAsync(TextFileUrl, string.Empty);

                string[] lines = { username, password, state };
                await System.IO.File.WriteAllLinesAsync(TextFileUrl, lines);

                return(RedirectToAction("Index", "Poll"));
            }
            else
            {
                switch (result.Value)
                {
                case InstaLoginResult.InvalidUser:
                    ViewData["ErrorMessage"] = "نام کاربری نامعتبر است";
                    break;

                case InstaLoginResult.BadPassword:
                    ViewData["ErrorMessage"] = "رمز عبور اشتباه است";
                    break;

                case InstaLoginResult.Exception:
                    ViewData["ErrorMessage"] = result.Info?.Message;
                    break;

                case InstaLoginResult.LimitError:
                    ViewData["ErrorMessage"] = "ارور دسترسی (باید 10 دقیقه صبر کنید)";
                    break;

                case InstaLoginResult.ChallengeRequired:
                    return(RedirectToAction("ChallengeRequired"));

                case InstaLoginResult.TwoFactorRequired:
                    return(RedirectToAction("TwoFactor"));
                }
            }
            ViewData["Username"] = username;
            ViewData["Password"] = password;
            return(View());
        }