Below is my C# code which I am using for connect SharePoint site.

When I try to access same SharePoint site from web page it's working fine and I able to access it But when I try to with below code I am getting error.

Microsoft.SharePoint.Client.IdcrlException: 'The sign-in name or password does not match one in the Microsoft account system.'

string targetSiteURL = "https://test.sharepoint.com/sites/SD/";

                var login = "[email protected]";
                var password = "password";
                SecureString securePass = new SecureString();

            foreach (char c in password.ToCharArray())

            //AuthenticationManager am = new AuthenticationManager();
            //using (var cc = am.GetSharePointOnlineAuthenticatedContextTenant(targetSiteURL, login, securePass))
            //    cc.ExecuteQuery();
            //    var count = cc.Web.Lists.Count;


            ClientContext context = new ClientContext(targetSiteURL);
            context.RequestTimeout = -1;
            context.AuthenticationMode = ClientAuthenticationMode.Default;

            Web web = context.Web;

            context.Credentials = new SharePointOnlineCredentials(login, securePass);


                //var str = "true";
            catch (Exception e)
                var error = e.ToString();

Before asking question here, I spend a lot of time on it but i didn't get any solution. If any one know the solution of it then that is very helpful for me.

Notes- I am using below packages in C#.

enter image description here

  • Is there multi-factor authentication enabled for this tenant? Apr 2, 2020 at 5:25
  • @GaneshSanap No not enable for this tenant.
    – KARAN
    Apr 2, 2020 at 12:32
  • @GaneshSanap can you please help if you have any idea.
    – KARAN
    Apr 2, 2020 at 12:33
  • Is Modern Auth enabled for SPO? The answer is likely "yes" as all tenants created within the past couple of years have had it enabled by default. You should be using a client id/secret pattern, not username and password.
    – user6024
    Apr 3, 2020 at 1:14


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.