public ActionResult ChangePassword(ChangePassword model) { if (ModelState.IsValid) { if (CurrentUser.Password != EncryptUtils.Encrypt(model.OldPassword).Trim()) { ModelState.AddModelError("", "Current password not correct"); return(View()); } if (string.IsNullOrEmpty(model.NewPassword)) { ModelState.AddModelError("", "You must enter your new password"); return(View()); } else { if (model.NewPassword != model.ConfirmPassword) { ModelState.AddModelError("", "Confirm password not correct"); return(View()); } else { UserBO.ChangePassword(CurrentUser.Id, EncryptUtils.Encrypt(model.NewPassword)); CurrentUser.Password = EncryptUtils.Encrypt(model.NewPassword); FormsAuthentication.SetAuthCookie(JsonConvert.SerializeObject(CurrentUser, Formatting.None), false); return(RedirectToAction("MyProfile", "User")); } } } return(View()); }
protected void btnChangePassword_Click(object sender, EventArgs e) { bool status = false; string newPwd = txtNewPassword.Text; try { if (Request.QueryString["key"] != null) { UserVO user = new UserVO(); string key = Request.QueryString["key"].ToString(); string temp = key; user.UserName = key.Substring(0, 7); user.ResetKey = key.Substring(7); user.Password = newPwd; status = userBO.ChangePassword(user); if (status) { lblUserMessage.Text = "Password has been updated successfully"; lblUserMessage.ForeColor = System.Drawing.Color.Green; lblUserMessage.Font.Bold = true; } else { lblUserMessage.Text = "Error in updating password. Please try again later."; lblUserMessage.ForeColor = System.Drawing.Color.Red; lblUserMessage.Font.Bold = true; } } else { lblUserMessage.Text = "URL not valid"; lblUserMessage.ForeColor = System.Drawing.Color.Red; lblUserMessage.Font.Bold = true; } } catch (CustomException cex) { lblUserMessage.Text = cex.Message; lblUserMessage.ForeColor = System.Drawing.Color.Red; lblUserMessage.Font.Bold = true; } catch (Exception ex) { ExceptionUtility.LogException(ex, "Error Page"); lblUserMessage.Text = ex.Message; lblUserMessage.ForeColor = System.Drawing.Color.Red; lblUserMessage.Font.Bold = true; } }
protected void btnChangePassword_Click(object sender, EventArgs e) { string userName = ""; bool status = false; string newPwd = txtNewPassword.Text; try { if (Session["UserName"].ToString() != null) { userName = Session["UserName"].ToString(); status = userBO.ChangePassword(userName, newPwd); if (status) { lblUserMessage.Text = "Password has been updated successfully"; lblUserMessage.ForeColor = System.Drawing.Color.Green; lblUserMessage.Font.Bold = true; } else { lblUserMessage.Text = "Error in updating password. Please try again later."; lblUserMessage.ForeColor = System.Drawing.Color.Red; lblUserMessage.Font.Bold = true; } } } catch (CustomException cex) { lblUserMessage.Text = cex.Message; lblUserMessage.ForeColor = System.Drawing.Color.Red; lblUserMessage.Font.Bold = true; } catch (Exception ex) { ExceptionUtility.LogException(ex, "Error Page"); lblUserMessage.Text = ex.Message; lblUserMessage.ForeColor = System.Drawing.Color.Red; lblUserMessage.Font.Bold = true; } }