Esempio n. 1
0
        public JsonResult UserPasswordChange(UserPasswordChangeModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    string sixAutomaticPassword = SaccoChapChap.Services.DAL.RandomString(6);
                    string encodePassword       = SaccoChapChap.Services.DAL.EncodePassword(sixAutomaticPassword);

                    List <UserPasswordChangeModel> Pintlist = _db.Query <UserPasswordChangeModel>(";Exec PasswordChange @UserID,@Password,@Remarks,@CreatedBy",
                                                                                                  new
                    {
                        UserID    = model.UserID,
                        Password  = encodePassword,
                        Remarks   = model.Remarks,
                        CreatedBy = User.Identity.Name
                    }).ToList();

                    //return Json(new { Result = "OK" });
                    return(Json(new { Result = "OK", Record = Pintlist }));
                }
                catch (Exception e)
                {
                    return(Json(new { Result = "ERROR", Message = e.Message }));
                }
            }
            else
            {
                var message = string.Join(" | ", ModelState.Values
                                          .SelectMany(v => v.Errors)
                                          .Select(e => e.ErrorMessage));

                return(Json(new { Result = "ERROR", Message = message }));
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> ChangePassword(UserPasswordChangeModel model)
        {
            Application_User appUser = _userManager.FindByNameAsync(model.UserName).Result;
            await _userManager.ChangePasswordAsync(appUser, model.OldPassword, model.NewPassword);

            return(Ok(new Response {
                Status = "Password Changed", Message = "Password changed successfully."
            }));
        }
Esempio n. 3
0
 public IActionResult ChangeUserPassword([FromBody] UserPasswordChangeModel userPasswordChange)
 {
     if (userPasswordChange == null ||
         string.IsNullOrEmpty(userPasswordChange.OldPassword) ||
         string.IsNullOrEmpty(userPasswordChange.NewPassword))
     {
         throw new MissingParameterException();
     }
     if (userPasswordChange?.OldPassword?.Length > Limits.MAX_PASSWORD)
     {
         throw new InputValueTooLargeException();
     }
     if (userPasswordChange?.NewPassword?.Length > Limits.MAX_PASSWORD)
     {
         throw new InputValueTooLargeException();
     }
     PwdManService.ChangeUserPassword(GetToken(), userPasswordChange);
     return(new JsonResult(true));
 }
Esempio n. 4
0
        public ActionResult ChangePassword(UserPasswordChangeModel model)
        {
            bool   Status  = false;
            string message = "";

            //Model Validation
            if (ModelState.IsValid)
            {
                #region Check if Current Password is correct
                var IsCorrect = IsPasswordCorrect(model.Password);
                if (!IsCorrect)
                {
                    ModelState.AddModelError("EmailExist", "Password is incorrect");
                    return(View(model));
                }
                #endregion

                #region Password hashing
                model.NewPassword     = Crypto.Hash(model.NewPassword);
                model.ConfirmPassword = Crypto.Hash(model.ConfirmPassword);
                #endregion

                #region Save data to database
                using (BloodDonorDBEntities db = new BloodDonorDBEntities())
                {
                    db.SaveChanges();
                    Status = true;
                }
                #endregion
            }
            else
            {
                message = "Invalid request";
            }

            ViewBag.Message = message;
            ViewBag.Status  = Status;
            return(View(model));
        }
Esempio n. 5
0
        public async Task <ActionResult <ApiResult <SessionPreview> > > ChangePassword([FromBody] UserPasswordChangeModel data, CancellationToken cancellationToken = default)
        {
            var user = this.RosettaUser;
            var pwd  = await this.UserRepository.GetUserPasswordAsync(user.Id, cancellationToken);

            if (pwd != null && data.OldPassword == null)
            {
                return(this.StatusCode(401, ApiResult.FromError <SessionPreview>(new ApiError(ApiErrorCode.InvalidCredentials, "Specified credentials were invalid."))));
            }

            if (pwd != null && !await this.Password.ValidatePasswordHashAsync(data.OldPassword, pwd))
            {
                return(this.StatusCode(401, ApiResult.FromError <SessionPreview>(new ApiError(ApiErrorCode.InvalidCredentials, "Specified credentials were invalid."))));
            }

            var npwd = await this.Password.CreatePasswordHashAsync(data.NewPassword);

            await this.UserRepository.UpdateUserPasswordAsync(user.Id, npwd, cancellationToken);

            var ruser = this.UserPreviewRepository.GetUser(user);
            var token = this.Jwt.IssueToken(ruser);

            return(this.Ok(ApiResult.FromResult(this.UserPreviewRepository.GetSession(ruser, token.Token, token.ExpiresAt, user.RequiresMfa))));
        }