DotNetNuke modules required an option to reset/change a users password. I set of trying all sorts of things as the ChangePassword function on the UserController required me to pass the old password which I did not know how to get.
After some more looking around I found that you can get the old password by using the UserController.GetPassword, I finished off my ChangePassword function and here it is below.
public enum PwdAction
{
ChangePassword,
ChangePasswordForceChange
}
public bool ChangePassword(int portalID, string Username, string newPassword, PwdAction action)
{
string sOldPassword;
bool bChangePassword;
UserInfo oUserInfo = UserController.GetUserByName(portalId, UserName);
sOldPassword = UserController.GetPassword(ref oUserInfo, "");
if (oUserInfo != null)
{
switch (action)
{
case Utilities.PwdAction.ChangePassword:
bChangePassword = UserController.ChangePassword(oUserInfo, sOldPassword, newPassword);
break;
case Utilities.PwdAction.ChangePasswordForceChange:
bChangePassword = UserController.ChangePassword(oUserInfo, sOldPassword, newPassword);
if (bChangePassword)
{
oUserInfo.Membership.UpdatePassword = true;
UserController.UpdateUser(oUserInfo.PortalID, oUserInfo);
}
break;
default:
Exception exc = new Exception(String.Format("Unknown action '{0}'", PwdAction.ToString()));
Exceptions.LogException(exc);
break;
}
}
return bChangePassword;
}