Ejemplo n.º 1
0
 /// <summary>
 /// Changes the password.
 /// </summary>
 /// <param name="oldPassword">The old password.</param>
 /// <param name="newPassword">The new password.</param>
 /// <param name="confirmNewPassword">The confirm new password.</param>
 /// <param name="resetPassword">The reset password.</param>
 /// <returns></returns>
 public ActionResult ChangePassword(string resetPassword)
 {
     UserInformation userInformation = new UserInformation();
     if (!string.IsNullOrEmpty(resetPassword))
     {
         userInformation.Password = resetPassword;
     }
     return View(userInformation);
 }
Ejemplo n.º 2
0
        public ActionResult ChangePassword(UserInformation userInformation)
        {
            if (userInformation.ChangePassword != userInformation.ConfirmPassword)
            {
                TempData["ErrorMessage"] = "Your new passwords do not match, please retype them and try again";
                return View(userInformation);
            }

            try
            {
                MembershipUser membershipUser = Membership.GetUser(HttpContext.User.Identity.Name, false);
                membershipUser.ChangePassword(userInformation.Password, userInformation.ChangePassword);
                TempData["SuccessMessage"] = "Your password has been sucessfully changed";
                return View(userInformation);
            }
            catch (Exception exception)
            {
                TempData["ErrorMessage"] = "Password change has failed because: " + exception.Message;
                return View(userInformation);
            }
        }
Ejemplo n.º 3
0
        public ActionResult ForgotPassword(string userName, string secretAnswer)
        {
            if (!String.IsNullOrEmpty(secretAnswer))
            {
                string resetPassword = Membership.Provider.ResetPassword(userName, secretAnswer);
                if (Membership.ValidateUser(userName, resetPassword))
                {
                    FormsAuthentication.SetAuthCookie(userName, false);
                    return RedirectToAction("ChangePassword", new { resetPassword = resetPassword });
                }
                else
                {
                    TempData["ErrorMessage"] = "Invalid Response";
                    return View();
                }
            }

            MembershipUser membershipUser = Membership.GetUser(userName, false);
            UserInformation userinformation = new UserInformation();
            if (membershipUser != null)
            {
                userinformation.SecretQuestion = membershipUser.PasswordQuestion;
                userinformation.UserName = userName;
            }
            else
            {
                TempData["ErrorMessage"] = "The user you have specified is invalid, please recheck your username and try again";
                userinformation.SecretQuestion = String.Empty;
            }

            return View(userinformation);
        }
Ejemplo n.º 4
0
 public ActionResult Register(UserInformation userInformation)
 {
     if (userInformation.Password != userInformation.ConfirmPassword)
     {
         TempData["ErrorMessage"] = "Registration failed! Your passwords must match, please re-enter and try again";
     }
     else
     {
         MembershipCreateStatus membershipCreateStatus = new MembershipCreateStatus();
         try
         {
             Membership.CreateUser(userInformation.UserName, userInformation.Password, userInformation.Email, userInformation.SecretQuestion, userInformation.SecretAnswer, true, out membershipCreateStatus);
             if (membershipCreateStatus == MembershipCreateStatus.Success)
             {
                 if (Membership.ValidateUser(userInformation.UserName, userInformation.Password))
                 {
                     FormsAuthentication.SetAuthCookie(userInformation.UserName, false);
                     if (!String.IsNullOrEmpty(userInformation.ReturnUrl))
                         return this.Redirect(userInformation.ReturnUrl);
                     else
                         return this.Redirect(FormsAuthentication.DefaultUrl);
                 }
                 else
                 {
                     TempData["ErrorMessage"] = "Login failed! Please make sure you are using the correct user name and password.";
                 }
             }
             else
             {
                 TempData["ErrorMessage"] = GetErrorMessage(membershipCreateStatus);
             }
         }
         catch (Exception exception)
         {
             TempData["ErrorMessage"] = exception.Message;
         }
     }
     //If failed, keep the registory page.
     return View("Register", userInformation);
 }