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.