Beispiel #1
0
        public static void ResetUserPassword(string username, string newPassword, bool sendEmail, SPWeb web)
        {
            if (Utils.BaseMembershipProvider().RequiresQuestionAndAnswer || !Utils.BaseMembershipProvider().EnablePasswordReset)
            {
                throw new Exception(LocalizedString.GetGlobalString("FBAPackWebPages", "ResetPasswordUnavailable"));
            }

            MembershipUser user     = Utils.BaseMembershipProvider().GetUser(username, false);
            string         password = user.ResetPassword();

            //Change the password to the specified password
            if (!String.IsNullOrEmpty(newPassword))
            {
                if (user.ChangePassword(password, newPassword))
                {
                    password = newPassword;
                }
                else
                {
                    throw new Exception(LocalizedString.GetGlobalString("FBAPackWebPages", "ResetPasswordChangePasswordError"));
                }
            }

            if (sendEmail)
            {
                MembershipRequest request = MembershipRequest.GetMembershipRequest(user, web);
                request.Password = password;

                MembershipRequest.SendResetPasswordEmail(request, web);
            }
        }