Пример #1
0
        public ChangePwdResult WdaChangePassword(string Email, string OldPassword, string NewPassword, string remoteAddress)
        {
            ChangePwdResult changePwdResult = new ChangePwdResult();

            changePwdResult = _storedProcedures.WdaChangePassword(Email, OldPassword, NewPassword, remoteAddress).First();

            if (changePwdResult.IsPasswordChanged == 1)
            {
                Utility.SendMailForPasswordChange(Email);
            }

            return(changePwdResult);
        }
Пример #2
0
        public async Task <ChangePwdResult> DoChangePwd(ChangePwdInfo request)
        {
            try
            {
                if (request.Old == request.New)
                {
                    throw new Exception("Old password = New password!");
                }

                if (request.New.Length < 8)
                {
                    throw new Exception("Password minimum length is 8 char!");
                }

                if (request.New.Length > 32)
                {
                    throw new Exception("Password maximum length is 32 char!");
                }

                if (!Misc.IsValidPassword(request.New))
                {
                    throw new Exception("Invalid password, character ' and \" are not allowed!");
                }

                var lastSendTime = (DateTime.UtcNow - _lastTime).TotalSeconds;
                if (lastSendTime <= 90)
                {
                    throw new Exception(
                              $"You need to wait at least 90 seconds before to try again! Last try was {lastSendTime} seconds ago.");
                }

                dynamic requestInfo = request;

                var result = await DataExchange.DoDataExchange((object)requestInfo);

                ChangePwdResult retVal = result.ToObject <ChangePwdResult>();

                if (retVal.Result)
                {
                    _lastTime = DateTime.UtcNow;
                }

                return(retVal);
            }
            catch (Exception e)
            {
                return(new ChangePwdResult(false, e.Message));
            }
        }
Пример #3
0
        public IHttpActionResult ChangePassword(string Email, string OldPassword, string NewPassword)
        {
            ChangePwdResult changeResult = userSvc.WdaChangePassword(Email, OldPassword, NewPassword, HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"]);

            if (changeResult.IsPasswordChanged == 1)
            {
                return(Ok(changeResult));
            }
            else
            {
                ModelState.AddModelError("", changeResult.Remarks);
            }

            return(ResponseMessage(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState.ToError())));
        }
Пример #4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (CurrentUser == null)
            {
                Login();
            }
            if (RequestHelper.IsPostBack(Request))
            {
                string          oldPwd     = Request["oldpassword"].Trim();
                string          newPwd     = Request["password"].Trim();
                string          confirmPwd = Request["confirm"].Trim();
                UsersBLL        usersBLL   = new UsersBLL();
                ChangePwdResult result     = usersBLL.ChangePwd(CurrentUser.userId, oldPwd, newPwd, confirmPwd);
                switch (result)
                {
                case ChangePwdResult.旧密码错误:
                    msg = "旧密码错误";
                    break;

                case ChangePwdResult.两次输入密码不一致:
                    msg = "两次输入密码不一致";
                    break;

                case ChangePwdResult.修改成功:
                    msg = "修改成功";
                    Session.Clear();
                    CookieHelper.Clear();
                    Response.Redirect("../account/Login.aspx");
                    break;

                case ChangePwdResult.用户不存在:
                    msg = "用户不存在";
                    break;

                default:
                    break;
                }
            }
        }
Пример #5
0
 public ActionResult Index(ChangePasswordInputModel model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             ChangePwdResult changePwd = this.userSvc.WdaChangePassword(User.Identity.Name, model.OldPassword, model.NewPassword, Request.ServerVariables["REMOTE_ADDR"]);
             if (changePwd.IsPasswordChanged == 1)
             {
                 return(View("Success"));
             }
             else
             {
                 ModelState.AddModelError("ErrorPwdChange", changePwd.Remarks);
             }
         }
         catch (ValidationException ex)
         {
             ModelState.AddModelError("", ex.Message);
         }
     }
     return(View(model));
 }