ChangePassword() public method

public ChangePassword ( string userName, string oldPassword, string newPassword ) : bool
userName string
oldPassword string
newPassword string
return bool
        public IHttpActionResult UpdatePassword(UpdatePass pass)
        {
            string str = "Password modification failed";

            if (!string.IsNullOrEmpty(pass.username) && !string.IsNullOrEmpty(pass.newPassword) && !string.IsNullOrEmpty(pass.oldP))
            {
                var MembershipService = new AccountMembershipService();
                try
                {
                    Membership.ApplicationName = "MES";
                    if (MembershipService.ChangePassword(pass.username, pass.oldP, pass.newPassword))
                    {
                        str = "Password reset complete";
                    }
                    else
                    {
                        return(BadRequest("Password modification failed"));
                    }
                }
                catch (Exception eJob)
                {
                    var error = string.Format("Job错误,执行aspnet_Membership_SetPassword出错,错误信息{0}", eJob.Message);
                    var resp  = new HttpResponseMessage(HttpStatusCode.InternalServerError)
                    {
                        ReasonPhrase = error,
                        Content      = new StringContent(error)
                    };

                    Loger.Error(eJob);
                    throw new HttpResponseException(resp);
                }
            }

            return(Ok(str));
        }
Ejemplo n.º 2
0
        public ActionResult PasswordReset(PasswordResetViewModel model)
        {
            string emailAddress = model.email;
            string user         = Membership.GetUserNameByEmail(emailAddress);

            AccountMembershipService.ChangePassword(user);
            TempData["tempMessage"] =
                "You have reset your password, please retrieve it from your email inbox and log on.";
            return(RedirectToAction("LogOn"));
        }