public ActionResult ChangePassword(ChangePasswordModel model)
        {
            if (ModelState.IsValid)
            {
                // ChangePassword will throw an exception rather
                // than return false in certain failure scenarios.
                bool changePasswordSucceeded;
                try
                {
                    a.MembershipUser currentUser = System.Web.Security.Membership.GetUser(User.Identity.Name, userIsOnline: true);
                    changePasswordSucceeded = currentUser.ChangePassword(model.OldPassword, model.NewPassword);
                }
                catch (Exception)
                {
                    changePasswordSucceeded = false;
                }

                if (changePasswordSucceeded)
                {
                    return(RedirectToAction("ChangePasswordSuccess"));
                }
                else
                {
                    ModelState.AddModelError("", "The current password is incorrect or the new password is invalid.");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Beispiel #2
0
        /// <summary>
        /// Change user password
        /// </summary>
        /// <param name="member">Member</param>
        /// <param name="oldPassword">Old password</param>
        /// <param name="newPassword">New Password</param>
        /// <returns>Success status</returns>
        public bool ChangePassword(MembershipUser member, string oldPassword, string newPassword)
        {
            bool changeSucceed;
            var passwordHistoryService = new PasswordsHistoryService();

            if (member == null || !Membership.ValidateUser(member.UserName, oldPassword))
                throw new Exception("The password you entered does not match our records, please try again.");
            // Verify that username and password arent the same.
            if (member.UserName == newPassword)
                throw new Exception("Password cannot be the same as Username");
            if (string.Compare(oldPassword, newPassword, StringComparison.Ordinal) == 0)
                throw new Exception("Your new password cannot be the same as your current password.");

            try
            {
                var memberId = (int) member.ProviderUserKey;
                if (passwordHistoryService.CheckUserPassword(memberId, newPassword))
                {
                    changeSucceed = member.ChangePassword(oldPassword, newPassword);
                    // if password was changed save it to the history
                    if (changeSucceed)
                        passwordHistoryService.Add(memberId, newPassword);
                    // Update the User profile in the database
                    Membership.UpdateUser(member);
                }
                else
                {
                    // Reads Change Password page node
                    var page = ((DynamicPublishedContent)_helper.ContentAtRoot().First())
                        .Descendant("ChangePassword");
                    var message = page.GetPropertyValue<string>("lastPasswordsValidationMessage");
                    throw new Exception(message);
                }
            }
            catch (MembershipPasswordException)
            {
                throw new Exception("The password is not strong enough");
            }
            catch(Exception ex)
            {
                // Create an error message with sufficient info to contact the user
                string additionalInfo = "User " + member.UserName + " was unable to change their password.";
                // Add the error message to the log4net output
                GlobalContext.Properties["additionalInfo"] = additionalInfo;
                logger.Error(ex);
                throw;
            }
            return changeSucceed;
        }
        /// <summary>
        /// Changes password and removes hash from DDS
        /// </summary>
        /// <param name="user"></param>
        /// <param name="newPassword"></param>
        /// <param name="hash"></param>
        /// <returns></returns>
        public bool ChangePassword(MembershipUser user, string newPassword, string hash)
        {
            bool success = false;
            //change password
            if (user != null)
            {
                // reset password to retrieve current password
                string resetPw = user.ResetPassword();
                success = user.ChangePassword(resetPw, newPassword);
                // clean up - remove reset link from dds
                if (!string.IsNullOrEmpty(hash))
                    _resetPasswordRespository.Delete(hash);
            }

            return success;
        }
Beispiel #4
0
        protected void ChangePasswordPushButton_Click(object sender, EventArgs e)
        {
            Guid userId = JocysCom.ClassLibrary.Security.Helper.GetUserId <Guid>(ResetKeyLabel.Text);
            var  user   = Data.User.GetUser(userId);

            System.Web.Security.MembershipUser muser = Membership.GetUser(user.UserName);
            // Reset password: Start
            string tempPassword = muser.ResetPassword();

            muser.ChangePassword(tempPassword, NewPassword.Text);
            Membership.UpdateUser(muser);
            // Reset password: End
            SuccessPanel.Visible        = true;
            ChangePasswordPanel.Visible = false;
            RedirectionPanel.Visible    = true;
        }
 public void ChangePassword(MembershipUser user, string oldPassword, string newPassword)
 {
     if (!user.ChangePassword(oldPassword, newPassword))
         throw new MembershipPasswordException("Could not change password.");
 }
 public void ChangePassword(MembershipUser user, string newPassword)
 {
     var resetPassword = user.ResetPassword();
     if (!user.ChangePassword(resetPassword, newPassword))
         throw new MembershipPasswordException("Could not change password.");
 }
		/// <summary>
        /// Change user password
        /// </summary>
        /// <param name="password"></param>
        /// <param name="newPassword"></param>
        /// <returns></returns>
        bool ChangePassword(MembershipUser user, string password, string newPassword)
        {
            return user.ChangePassword(password, newPassword);
        }
Beispiel #8
0
 /// <summary>
 /// Change user password
 /// </summary>
 /// <param name="user">Membership user</param>
 /// <param name="newPassword">new password</param>
 /// <returns>Return true if password changed</returns>
 public bool ChangePassword(MembershipUser user, string newPassword)
 {
     return user.ChangePassword(user.ResetPassword(), newPassword);
 }
 /// <summary>
 /// this method is used to change the user password  //Developed by swaraj on 19 feb 2010
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void lbtnSave_Click(object sender, EventArgs e)
 {
     try
     {
         objMembershipUser = Membership.GetUser(User.Identity.Name);
         if (Membership.ValidateUser(User.Identity.Name.ToString(), txtOldPwd.Text.ToString()))
         {
             objMembershipUser.ChangePassword(txtOldPwd.Text.ToString(), txtNewPwd.Text.ToString());
             lblMsg.ForeColor = System.Drawing.Color.Green;
             lblMsg.Text = "Password has been changed successfully";
             txtNewPwd.Text = "";
             txtOldPwd.Text = "";
             txtConfirmPwd.Text = "";
         }
         else
         {
             lblMsg.ForeColor = System.Drawing.Color.Red;
             lblMsg.Text = "Entered old password is incorrect";
         }
     }
     catch (Exception ex)
     {
         lblMsg.ForeColor = System.Drawing.Color.Red;
         lblMsg.Text = ex.Message.ToString();
     }
 }
Beispiel #10
0
 public bool ChangePassword(MembershipUser user, string oldPassword, string newPassword)
 {
     return user.ChangePassword(oldPassword, newPassword);
 }
 public void ChangePassword(MembershipUser membershipUser, string newPassword)
 {
     string tempPassword = membershipUser.ResetPassword();
     membershipUser.ChangePassword(tempPassword, newPassword);
 }
Beispiel #12
0
 public bool ChangePassword(string password)
 {
     return(membershipUser.ChangePassword(membershipUser.ResetPassword(), password));
 }
Beispiel #13
0
        public static bool ChangeUserPassword(MembershipUser user, string newPassword, string verificationId)
        {
            try
            {
                string newPass = string.Empty;
                try
                {
                    newPass = user.ResetPassword();
                }
                catch (Exception exception)
                {
                    if (exception.Message.Contains("user account has been locked out"))
                    {
                        user.UnlockUser();
                        newPass = user.ResetPassword();
                    }
                    else
                        ErrorDatabaseManager.AddException(exception, exception.GetType());
                }
                bool changed = user.ChangePassword(newPass, newPassword);
                var tempUser = GetMember(user.UserName);

                SendEmailForPasswordChanged(user.Email, tempUser.DerbyName);
                var dc = new ManagementContext();
                var verify = dc.EmailVerifications.Where(x => x.VerificationId == new Guid(verificationId)).FirstOrDefault();
                if (verify != null)
                {
                    dc.EmailVerifications.Remove(verify);
                    int c = dc.SaveChanges();
                }
                return changed;
            }
            catch (Exception exception)
            {
                ErrorDatabaseManager.AddException(exception, exception.GetType());

            }
            return false;
        }
 public virtual bool ChangePassword(MembershipUser membershipUser, string oldPassword, string newPassword)
 {
     return membershipUser.ChangePassword(oldPassword, newPassword);
 }