none
SharePoint Online MFA - CSOM - The sign-in name or password does not match one in the Microsoft account system. RRS feed

  • Question

  • Hi All,

    I am authenticating SharePoint online url as given below. I am getting error "The sign-in name or password does not match one in the Microsoft account system.

     using (ClientContext clientContext = new ClientContext("https://test.sharepoint.com/sites/Z-box/"))
                    {
                        var password = new SecureString();
                        SecureString securePassword = new SecureString();
                        foreach (char c in "Pa$$word".ToCharArray())
                        {
                            securePassword.AppendChar(c);
                        }
                        SharePointOnlineCredentials spcr= new SharePointOnlineCredentials("tuser@domain.com", securePassword);
                        clientContext.Credentials = spcr;
                        Web site = clientContext.Web;
                        clientContext.Load(site);
                        var lists = site.Lists;
                        List list1 = clientContext.Web.Lists.GetByTitle("Depart");
                        CamlQuery camlQuery = CamlQuery.CreateAllItemsQuery();
                        Microsoft.SharePoint.Client.ListItemCollection items = list1.GetItems(camlQuery);
                        clientContext.Load(items);
                        clientContext.ExecuteQuery();

    }

    I used to login the url with credentials along with security code. I am getting the error while authenticate using CSOM.

    Thanks & Regards

    Suresh Sankaran

    Friday, August 23, 2019 10:00 AM

All replies

  • FYI

    https://knowledge-junction.com/2017/12/24/office-365-connecting-to-sharepoint-online-site-using-csom-when-multi-factor-authentication-mfa-is-enabled-for-the-user/


    Justin Liu Office Apps & Services MVP, MCSE
    Senior Software Engineer
    Please Vote and Mark as Answer if it helps you.

    Monday, August 26, 2019 1:32 AM
  • Hi Suresh,

    Please check the login user name and password again, try to use the IE browser to access the list "Depart" to check if it works. And try to use the code below.

    string siteUrl = "https://test.sharepoint.com/sites/Z-box";
    string userName = "dennis@test.onmicrosoft.com";
    string password = "xxxxxx";
    
    var securePassword = new SecureString();
    foreach (char c in password.ToCharArray()) securePassword.AppendChar(c);
    using (ClientContext clientContext = new ClientContext(siteUrl))
    {
    	clientContext.Credentials = new SharePointOnlineCredentials(userName, securePassword);
    	Web site = clientContext.Web;
    	clientContext.Load(site);
    	var lists = site.Lists;
    	List list1 = clientContext.Web.Lists.GetByTitle("Depart");
    	CamlQuery camlQuery = CamlQuery.CreateAllItemsQuery();
    	Microsoft.SharePoint.Client.ListItemCollection items = list1.GetItems(camlQuery);
    	clientContext.Load(items);
    	clientContext.ExecuteQuery();
    	foreach(var item in items)
    	{
    		Console.WriteLine(item["Title"]);
    	}
    }

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Monday, August 26, 2019 1:37 AM
    Moderator
  • Hi Dennis,

    I have tried the given code but I am getting the following error

    The sign-in name or password does not match one in the Microsoft account system.

    Monday, August 26, 2019 5:40 AM
  • Hi Suresh,

    Please make sure the username format like xxx@tenant.onmicrosoft.com.

    And check if the password of the user is incorrect or is expired.

    And try to use OfficeDevPnP.Core.AuthenticationManager in CSOM C# code.

    var authManager = new AuthenticationManager();
    var ctx = authManager.GetWebLoginClientContext("https://test.sharepoint.com/sites/Z-box");
    Web web = ctx.Web;

    More information:

    SharePoint Online: Using CSOM with an account configured with Multi-factor Authentication (MFA)

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Monday, August 26, 2019 7:13 AM
    Moderator
  • Hi Dennis,

    My username format will not be like as follows, xxx@tenant.onmicrosoft.com. 

    My user name is "xxx@domain.com". The "onmicrosoft" will not be part of user name. 

    Already I have tried the given approach but still no luck on it.

    var authManager = new AuthenticationManager();
    var ctx = authManager.GetWebLoginClientContext("https://test.sharepoint.com/sites/Z-box");
    Web web = ctx.Web;

    The above approach did not raise any error but my code is not executing after this line 

    var authManager = new AuthenticationManager();

    Please suggest me on it.

    Thanks & Regards

    Suresh Sankaran


    Monday, August 26, 2019 9:13 AM
  • Hi Suresh,

    Per my knowledge, the CSOM has dependency on UserProfile service, if SharePoint does not find user in user profile, it simply does not authenticate users, thus external users are not part of user profiles that's why they can't be authenticated using CSOM.

    Please use the SharePoint Online account(xxx@tenant.onmicrosoft.com) to check if it works.

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Monday, August 26, 2019 9:19 AM
    Moderator