private static void FirstimeLoginChangePassword()
        {
            TreasuryDataContext tdc = new TreasuryDataContext();
            List<string> defaultpassword = new List<string>() { "NCO", null, "invalid password", "Account locked", "" };
            var passwordchangeusersnames = (from u in tdc.CybersourceGatewayTranDownloadTrackings
                                            where u.ReportDate.Equals(DateTime.Parse(reportDate)) && u.isDownLoadSuccess.Value.Equals(false) && !(defaultpassword.Contains(u.NewPasswordSet))
                                            select u);

            foreach (CybersourceGatewayTranDownloadTracking t in passwordchangeusersnames)
            {

                string organizationId = t.UserName;
                string username = t.UserName;
                string password = t.NewPasswordSet;
                string newpassword = "";
                string merchantid = t.MerchantId;

                List<string> validmessage = new List<string>();
                validmessage.Add("Welcome to the CyberSource Business Center");
                validmessage.Add("The specified login credentials are incorrect");
                validmessage.Add("The specified user name has been locked.");

                using (var browser = new IE("https://ebc.cybersource.com/ebc/login/Login.do#"))
                {

                    browser.Link(Find.ByText("change")).Click();
                    browser.TextField(Find.ByName("organizationId")).TypeText(organizationId);
                    browser.TextField(Find.ByName("username")).TypeText(username);
                    browser.TextField(Find.ByName("password")).TypeText(password);
                    browser.Button(Find.ByValue("Login")).Click();

                   if (browser.ContainsText(validmessage[0]) || browser.ContainsText(validmessage[1]) || browser.ContainsText(validmessage[2]))
                    {
                        if (browser.ContainsText(validmessage[0]))
                            newpassword = password;
                        else if (browser.ContainsText(validmessage[1]))
                            newpassword = "******";
                        else
                            newpassword = "******";

                        tdc.ExecuteCommand("update dbo.T_CybersourceGatewayMerchantConfig set Password='******' where MerchantId = '" + merchantid + "'");
                    }
                    else
                    {
                        //newpassword = "******" ;
                        //browser.TextField(Find.ByName("password")).TypeText(password);
                        //browser.TextField(Find.ByName("newPassword")).TypeText(newpassword);
                        //browser.TextField(Find.ByName("newPasswordConfirm")).TypeText(newpassword);
                        //browser.Button(Find.ByValue("Submit")).Click();

                        //if (browser.ContainsText("Secret Profile Setup"))
                        //{
                        //    if (!(browser.TextField(Find.ByName("answer")).Text.Length > 1))
                        //    {
                        //        browser.TextField(Find.ByName("answer")).TypeText("NCO");
                        //    }

                        //    browser.Button(Find.ByValue("Submit Request")).Click();

                        //    string sql = "Update dbo.T_CybersourceGatewayTranDownloadTracking set NewPasswordSet= '" + newpassword + "' where CybersourceGatewayTranDownloadTracking_id=" + t.CybersourceGatewayTranDownloadTracking_id;
                        //    tdc.ExecuteCommand(sql);

                        //    tdc.ExecuteCommand("update dbo.T_CybersourceGatewayMerchantConfig set Password='******' where MerchantId = '" + merchantid + "'");

                        //}
                        //else
                        //{
                        //    browser.Back();
                        //    newpassword = "******";
                        //    browser.TextField(Find.ByName("password")).TypeText(password);
                        //    browser.TextField(Find.ByName("newPassword")).TypeText(newpassword);
                        //    browser.TextField(Find.ByName("newPasswordConfirm")).TypeText(newpassword);
                        //    browser.Button(Find.ByValue("Submit")).Click();

                        //    if (browser.ContainsText("Secret Profile Setup"))
                        //    {
                        //        if (!(browser.TextField(Find.ByName("answer")).Text.Length > 1))
                        //        {
                        //            browser.TextField(Find.ByName("answer")).TypeText("NCO");
                        //        }

                        //        browser.Button(Find.ByValue("Submit Request")).Click();

                        //        string sql = "Update dbo.T_CybersourceGatewayTranDownloadTracking set NewPasswordSet= '" + newpassword + "' where CybersourceGatewayTranDownloadTracking_id=" + t.CybersourceGatewayTranDownloadTracking_id;
                        //        tdc.ExecuteCommand(sql);

                        //        tdc.ExecuteCommand("update dbo.T_CybersourceGatewayMerchantConfig set Password='******' where MerchantId = '" + merchantid + "'");

                        //    }
                        //    else
                        //    {
                                //browser.Back();

                                for (int i = 12; i <= 30; i++)
                                {

                                    newpassword = "******" + i.ToString();
                                    browser.TextField(Find.ByName("password")).TypeText(password);
                                    browser.TextField(Find.ByName("newPassword")).TypeText(newpassword);
                                    browser.TextField(Find.ByName("newPasswordConfirm")).TypeText(newpassword);
                                    browser.Button(Find.ByValue("Submit")).Click();

                                    if (browser.ContainsText("Secret Profile Setup"))
                                    {
                                        if (!(browser.TextField(Find.ByName("answer")).Text.Length > 1))
                                        {
                                            browser.TextField(Find.ByName("answer")).TypeText("NCO");
                                        }

                                        browser.Button(Find.ByValue("Submit Request")).Click();

                                        string sql = "Update dbo.T_CybersourceGatewayTranDownloadTracking set NewPasswordSet= '" + newpassword + "' where CybersourceGatewayTranDownloadTracking_id=" + t.CybersourceGatewayTranDownloadTracking_id;
                                        tdc.ExecuteCommand(sql);

                                        tdc.ExecuteCommand("update dbo.T_CybersourceGatewayMerchantConfig set Password='******' where MerchantId = '" + merchantid + "'");
                                        break;
                                    }
                                    else if (browser.ContainsText("Your new password cannot be a previously used password."))
                                    {
                                        browser.Back();

                                    }

                                    else if (browser.ContainsText("You cannot change your password more than three times in 24 hours"))
                                    {
                                        browser.Back();
                                        browser.Back();
                                        break;

                                    }
                                //}
                            //}
                       }
                    }
               }
            }
        }
        private static void PasswordChange()
        {
            bool nextstage = false;

            var passwordchangeusersnames = (from u in tdc.CybersourceGatewayTranDownloadTrackings
                                            where u.ReportDate.Equals(DateTime.Parse(reportDate)) && u.isDownLoadSuccess.Value.Equals(false) && u.NewPasswordSet.Equals(null)
                                 select u);
            foreach (CybersourceGatewayTranDownloadTracking t in passwordchangeusersnames)
            {
                string merchantid = t.MerchantId ;
                string username = t.UserName;
                string password="******";
                string organizationId = t.UserName;
                string newpassword="";

                List<string> validmessage = new List<string>();
                validmessage.Add("Welcome to the CyberSource Business Center");
                validmessage.Add("The specified user name has been locked.");

                using (var browser = new IE("https://ebc.cybersource.com/ebc/login/Login.do#"))
                {

                    browser.Link(Find.ByText("change")).Click();
                    browser.TextField(Find.ByName("organizationId")).TypeText(organizationId);
                    browser.TextField(Find.ByName("username")).TypeText(username);
                    browser.TextField(Find.ByName("password")).TypeText(password);
                    browser.Button(Find.ByValue("Login")).Click();

                    if (browser.ContainsText(validmessage[0]) || browser.ContainsText(validmessage[1]) )
                    {

                        if (browser.ContainsText(validmessage[0]))
                        { newpassword = password; }
                        else if (browser.ContainsText(validmessage[1]))
                        { newpassword = "******"; }

                        tdc.ExecuteCommand("update dbo.T_CybersourceGatewayTranDownloadTracking set NewPasswordSet='" + newpassword + "' where MerchantId = '" + merchantid + "'");
                        tdc.ExecuteCommand("update dbo.T_CybersourceGatewayMerchantConfig set Password='******' where MerchantId = '" + merchantid + "'");

                    }
                    else if (browser.ContainsText("Secret Profile Setup"))
                    {
                        if (!(browser.TextField(Find.ByName("answer")).Text.Length > 1))
                        {
                            browser.TextField(Find.ByName("answer")).TypeText("NCO");
                        }

                        browser.Button(Find.ByValue("Submit Request")).Click();
                        string sql = "Update dbo.T_CybersourceGatewayTranDownloadTracking set NewPasswordSet= '" + newpassword + "' where CybersourceGatewayTranDownloadTracking_id=" + t.CybersourceGatewayTranDownloadTracking_id;
                        tdc.ExecuteCommand(sql);
                        tdc.ExecuteCommand("update dbo.T_CybersourceGatewayMerchantConfig set Password='******' where MerchantId = '" + merchantid + "'");

                    }
                    else
                    {
                        browser.Back();
                        password = "******";
                        browser.Link(Find.ByText("change")).Click();
                        browser.TextField(Find.ByName("organizationId")).TypeText(organizationId);
                        browser.TextField(Find.ByName("username")).TypeText(username);
                        browser.TextField(Find.ByName("password")).TypeText(password);
                        browser.Button(Find.ByValue("Login")).Click();

                        if (browser.ContainsText(validmessage[0]) || browser.ContainsText(validmessage[1]))
                        {

                            if (browser.ContainsText(validmessage[0]))
                            { newpassword = password; }
                            else if (browser.ContainsText(validmessage[1]))
                            { newpassword = "******"; }

                            tdc.ExecuteCommand("update dbo.T_CybersourceGatewayTranDownloadTracking set NewPasswordSet='" + newpassword + "' where MerchantId = '" + merchantid + "'");
                            tdc.ExecuteCommand("update dbo.T_CybersourceGatewayMerchantConfig set Password='******' where MerchantId = '" + merchantid + "'");

                        }
                        else if (browser.ContainsText("Secret Profile Setup"))
                        {
                            if (!(browser.TextField(Find.ByName("answer")).Text.Length > 1))
                            {
                                browser.TextField(Find.ByName("answer")).TypeText("NCO");
                            }

                            browser.Button(Find.ByValue("Submit Request")).Click();
                            string sql = "Update dbo.T_CybersourceGatewayTranDownloadTracking set NewPasswordSet= '" + newpassword + "' where CybersourceGatewayTranDownloadTracking_id=" + t.CybersourceGatewayTranDownloadTracking_id;
                            tdc.ExecuteCommand(sql);
                            tdc.ExecuteCommand("update dbo.T_CybersourceGatewayMerchantConfig set Password='******' where MerchantId = '" + merchantid + "'");

                        }
                        else
                        {

                            nextstage = step1_RequestForgottenPassword(organizationId, username);

                            if (nextstage)
                                nextstage = step2_RecoverPassword(organizationId, username, ref password);

                            string sql = "Update dbo.T_CybersourceGatewayTranDownloadTracking set NewPasswordSet= '" + password + "' where CybersourceGatewayTranDownloadTracking_id=" + t.CybersourceGatewayTranDownloadTracking_id;
                            tdc.ExecuteCommand(sql);

                            tdc.ExecuteCommand("update dbo.T_CybersourceGatewayMerchantConfig set Password='******' where MerchantId = '" + merchantid + "'");

                        }
                    }
                }
            }
        }
        public void Navigating()
        {
            using (var browser =
                new IE())
            {
                browser.AutoClose = false;
                browser.ShowWindow(NativeMethods.WindowShowStyle.Minimize);
                browser.ShowWindow(NativeMethods.WindowShowStyle.Maximize);

            browser.GoTo("http://www.bing.com");

            browser.GoTo("http://www.pluralsight.com");

            browser.Back();

            browser.Forward();
            }
        }