Oct 04 2022 12:42 AM
Hello,
I've been trying this simple CSOM code:
string siteCollectionUrl = "https://ieszambia.sharepoint.com/"; 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?
Oct 04 2022 01:31 AM
@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:
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.
Oct 04 2022 01:52 AM - edited Oct 04 2022 03:12 AM
Oct 04 2022 06:45 AM
Solution@spaieszambiacom
Mhm.... i normally use the "PnP.Framework" Library and this code
SecureString securePassword = new NetworkCredential("", password).SecurePassword;
Oct 04 2022 11:48 AM