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

Hong Guan Lim 20 Reputation points
2024-06-14T05:30:32.3933333+00:00

This is my console app project. Previously it was running perfectly but last week it suddenly cannot run. When I try locally, it shows me this error: "The sign-in name or password does not match one in the Microsoft account system".

What I tried:

Manually login to the Sharepoint Website using the same account and password. It is able to login and able to access to the folder that I wish to pull.

When I login to the Sharepoint Website using the same account and password, it does not request me to verify with phone call, sms etc. So I suspect this account is hasn't enabled MFA.

Note: This is not my account, this is my client's account, so I don't have much permission to check.

Below is my code:

using (ClientContext ctx = new ClientContext(ConfigurationManager.AppSettings.Get("SharePointApiUrl")))
{
     string password = ConfigurationManager.AppSettings.Get("SharePointPassword");
     string account = ConfigurationManager.AppSettings.Get("SharePointAccount");
     var secret = new System.Security.SecureString();
     foreach (char c in password)
     {
           secret.AppendChar(c);
     }
     ctx.Credentials = new SharePointOnlineCredentials(account, secret);
     ctx.Load(ctx.Web);
     ctx.ExecuteQuery();
}

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
10,108 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,550 questions
0 comments No comments
{count} votes

Accepted answer
  1. Emily Du-MSFT 43,421 Reputation points Microsoft Vendor
    2024-06-20T08:46:29.5233333+00:00

    I'm glad to hear you solve the problem, if you have any issue about SharePoint, you are welcome to raise a ticket in this forum.

    By the way, since the Microsoft Q&A community has a policy that "The question author cannot accept their own answer. They can only accept answers by others.". So, I would make a brief summary of this thread.

    You could click the "Accept Answer" button for this summary to close this thread, and this can make it easier for other community member's to see the useful information when reading this thread. Thanks for your understanding!

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

    Issue Symptom:

    When OP try locally, console app project shows me this error: "The sign-in name or password does not match one in the Microsoft account system".

    What OP tried:

    Manually login to the SharePoint website by using the same account and password. It is able to login and able to access to the folder.

    Login to the SharePoint website by using the same account and password, it does not request to verify with phone call, SMS etc. So, OP suspects this account is not enabled MFA.

    Below is code:

    using (ClientContext ctx = new ClientContext(ConfigurationManager.AppSettings.Get("SharePointApiUrl"))) 
    {      
        string password = ConfigurationManager.AppSettings.Get("SharePointPassword");      
        string account = ConfigurationManager.AppSettings.Get("SharePointAccount");      
        var secret = new System.Security.SecureString();      
        foreach (char c in password)      
         {            secret.AppendChar(c);      
         }      
        ctx.Credentials = new SharePointOnlineCredentials(account, secret);      
        ctx.Load(ctx.Web);      
        ctx.ExecuteQuery();
    

    Current status:

    OP solved this. OP excluded the user from Legacy Authentication.

    Here is the reference: https://help.orchid.systems/sage300addons/Content/Shared/ModuleOptions/Office365-Legacy-Authentication.htm

    0 comments No comments

3 additional answers

Sort by: Most helpful
  1. 感恩的❤ 155 Reputation points
    2024-06-14T06:30:35.76+00:00

    Yes!MFA/Modern Auth is the issue. You shouldn't be using a username/password as this will fail with modern auth and is a bad security practice. Instead, register a SharePoint Addin with the appropriate permission and leverage the Client ID/Secret.

    Plz read this carefully:https://docs.microsoft.com/sharepoint/dev/sp-add-ins/register-sharepoint-add-ins


    Some tips:

    1. For MFA Authentication, please download and install OfficeDevPnP.Core using Nuget:

    User's image

    static void Main(string[] args)
    {
    string siteUrl = "https://XXXXXX.sharepoint.com/sites/DocWebTest";
    var authManager = new OfficeDevPnP.Core.AuthenticationManager();
    // This method calls a pop up window with the login page and it also prompts
    // for the multi factor authentication code.
    ClientContext ctx = authManager.GetWebLoginClientContext(siteUrl);
    // The obtained ClientContext object can be used to connect to the SharePoint site.
    Web web = ctx.Web;
    ctx.Load(web, w => w.Title);
    ctx.ExecuteQuery();
    Console.WriteLine("You have connected to {0} site, with Multi Factor Authentication enabled!!", web.Title);
    }
    

  2. 感恩的❤ 155 Reputation points
    2024-06-14T06:34:53.0266667+00:00

    So I suspect this account is hasn't enabled MFA

    Yes, that's the real problem! Plz enable it first, and then you shouldn't be using a username/password as this will fail with modern auth and is a bad security practice. Instead, register a SharePoint Addin with the appropriate permission and leverage the Client ID/Secret.

    For more please read How to Use WFA with SharePoint?


    Several tips:

    For MFA Authentication, please download and install OfficeDevPnP.Core using Nuget:

    Rs9XW


  3. Emily Du-MSFT 43,421 Reputation points Microsoft Vendor
    2024-06-18T08:57:20.08+00:00

    Here are tips for you to troubleshoot the issue:

    1.Clear the system default browser cache, then try following codes.

    using (ClientContext ctx = new ClientContext(ConfigurationManager.AppSettings.Get("SharePointApiUrl")))
    {
         string password = ConfigurationManager.AppSettings.Get("SharePointPassword");
         string account = ConfigurationManager.AppSettings.Get("SharePointAccount");
         var secret = new System.Security.SecureString();
         foreach (char c in password)
         {
               secret.AppendChar(c);
         }
         ctx.Credentials = new SharePointOnlineCredentials(account, secret);
         ctx.Load(ctx.Web);
         ctx.ExecuteQuery();
    }
    

    2.Contact with admin to check whether the account with MFA enabled.

    3.Without the login page, you could use SharePoint App-Only method to access.

    https://video2.skills-academy.com/en-us/sharepoint/dev/solution-guidance/security-apponly-azureacs


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.