0

I have a method like this :

string siteUrl = "https://yourtenant.sharepoint.com/sites/yoursite";
string userName = "[email protected]";
string password = "yourpassword";

SecureString securePassword = new SecureString();
foreach (char c in password)
{
    securePassword.AppendChar(c);
}

try
{
    using (ClientContext context = new ClientContext(siteUrl))
    {
        context.Credentials = new SharePointOnlineCredentials(userName, securePassword);
        Web web = context.Web;
        context.Load(web, w => w.Title);
        context.ExecuteQuery();

        Console.WriteLine("Authenticated successfully. Site title is: " + web.Title);
    }
}
catch (Exception ex)
{
    Console.WriteLine("Authentication failed: " + ex.Message);
}

I don't see anything strange about it. I've checked and double and even triple checked the credentials and they're fine and work through a browser. MFA is turned off. But when the code runs it complains that the username and/or password doesn't match what's in the microsoft system.

1 Answer 1

1

SharePointOnlineCredentials uses a deprecated authentication protocol which can be enabled and disabled at the tenant level via command.

You can check the status of LegacyAuthProtocolsEnabled using:

Get-SPOTenant | select *legacy* | format-list

Not entirely sure if these legacy protocols will be usable for much longer. In an case, you will do well to switch to a better, newer authentication method.

See also,

Authentication with SharePoint Online in Microsoft 365 and simple console application

SharePoint online authantication when using SharePointOnlineCredentials

https://mspmagic.com/documentation/basic-authentication-for-sharepoint-online/

Edit:

The error,

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

Can also appear when LegacyAuthProtocolsEnabled is enabled but MFA is turned on for the provided account. See also, No Longer Able to Authenticate to SharePoint

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.