I have a Sharepoint site that uses Forms Based Authentication. I would like to discover the last password updated date and the creation, for the purpose of discovering whether they have changed their password since the account was created. I found a question on here already that seems to explain how to do this, but the code is not working for me. Here is a link to that question:
How to force change password on first login for FBA user?
The problem is, I am encountering the same error that the original poster encountered, I am getting an exception "The method or operation is not implemented." on this line:
System.Web.Security.MembershipUser user = System.Web.Security.Membership.GetUser(currentUser.LoginName)
Below the original post is another post seeming to indicate how he solved the issue, I tried wrapping my code in that but it still throws the same error. Below is a complete listing of the code for my non visual webpart, can you help me find out how to get the userinfo for the logged in user? I will also accept as an answer, a way to get the userid of the currently logged in user, because with that I can query the database directly to retrieve the information.
I am using Sharepoint2013, VisualStudio2013, and SharePoint 2013 FBA Pack
using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration.Claims;
namespace mysharepointproject.CheckPassword
{
[ToolboxItemAttribute(false)]
public class CheckPassword : WebPart
{
protected override void CreateChildControls()
{
Boolean PasswordChangeRequired = false;
SPUser currentUser = SPContext.Current.Web.CurrentUser;
if (SPSecurity.AuthenticationMode == System.Web.Configuration.AuthenticationMode.Forms)
{
SPClaimProviderManager mgr = SPClaimProviderManager.Local;
if (mgr != null)
{
SPClaim userLogonNameClaim = mgr.DecodeClaim(SPContext.Current.Web.CurrentUser.LoginName);
SPOriginalIssuerType issuerType = SPOriginalIssuers.GetIssuerType(userLogonNameClaim.OriginalIssuer);
if (Convert.ToString(issuerType).Equals("Forms"))
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
//The line below fails with The method or operation is not implemented.
System.Web.Security.MembershipUser user = System.Web.Security.Membership.GetUser(currentUser.LoginName);
if (user != null)
{
if (user.LastPasswordChangedDate == user.CreationDate)
{
PasswordChangeRequired = true;
}
}
});
}
}
}
if (PasswordChangeRequired)
{
//redirect to the page where users changes their password
HttpContext.Current.Response.Redirect("~/SitePages/cp.aspx");
}
}
}
}