Sharepoint online CSOM error

New Contributor



I've been trying this simple CSOM code:

string siteCollectionUrl = ""; string userName = "email address removed for privacy reasons"; string password = "Put00745"; // Namespace: Microsoft.SharePoint.Client ClientContext ctx = new ClientContext(siteCollectionUrl); // Namespace: System.Security SecureString secureString = new SecureString(); password.ToList().ForEach(secureString.AppendChar); // Namespace: Microsoft.SharePoint.Client ctx.Credentials = new SharePointOnlineCredentials(userName, secureString); // Namespace: Microsoft.SharePoint.Client Site site = ctx.Site; ctx.Load(site); ctx.ExecuteQuery(); return View(site.Url.ToString());



and I keep getting the following error: the sign-in name or password does not match one in the microsoft account. 


Even though I can log into sharepoint using those same credentials. ITs driving me crazy, what am I doing wrong? 

4 Replies

@spaieszambiacom If multi-factor authentication (MFA) is enabled for this user account, use M365 app password instead of normal password.


Check below threads for more information:

  1. Use App Password to Authenticate with PowerShell PnP 
  2. Connect-SPOService : The sign-in name or password does not match one in the Microsoft account system 

Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

Hi ganeshsanap,

Thank you for your quick response. Thats thing. MFA is actually disabled. Thats why itsdriving me crazy. Do you have any other suggestions?

Kind Regards
best response confirmed by spaieszambiacom (New Contributor)


Mhm.... i normally use the "PnP.Framework" Library and this code

SecureString securePassword = new NetworkCredential("", password).SecurePassword;

PnP.Framework.AuthenticationManager auth = new PnP.Framework.AuthenticationManager(username,securePassword);
ClientContext ctx = auth.GetContext(siteUrl);

Thank you very very much. This as worked. You've saved me a great headache. Thank you