Archive for November, 2008|Monthly archive page

DotNetNuke Reset Password

When I use DotNetNuke.Entities.Users.UserController.ResetPassword(), I assume this method will set the password length to the length I defined in Membership Provider Settings, but which is not the case. So I have to manually create a new password with the minimum password length and change the current password.

Here is the code:

DotNetNuke.Entities.Users.UserInfo userInfo = DotNetNuke.Entities.Users.UserController.GetUserByName(PortalId, UserName);

DotNetNuke.Security.Membership.MembershipProvider membershipProvider = DotNetNuke.Security.Membership.MembershipProvider.Instance();

if (membershipProvider.PasswordFormat == DotNetNuke.Security.Membership.PasswordFormat.Encrypted)

{

string oldPassword = DotNetNuke.Entities.Users.UserController.GetPassword(ref userInfo, userInfo.Membership.PasswordAnswer);

string newPassword = DotNetNuke.Entities.Users.UserController.GeneratePassword(membershipProvider.MinPasswordLength);

DotNetNuke.Entities.Users.UserController.ChangePassword(userInfo, oldPassword, newPassword);

}

else

{

DotNetNuke.Entities.Users.UserController.ResetPassword(userInfo, userInfo.Membership.PasswordAnswer);

}

The method GetPassword() will only return the password if the membership provider supports and is using a password encryption method that supports decryption.