예제 #1
0
        public async Task <ChangeMyUserPasswordResponse> ChangeMyUserPasswordAsync(ChangeMyUserPasswordRequest request)
        {
            var response = new ChangeMyUserPasswordResponse();
            var user     = await _users.FirstOrDefaultAsync(d => d.Id == request.Id);

            if (user == null)
            {
                return(response.ReturnWithCode(AuthenticationMessageHelper.Code.ChangeMyUserPasswordDoesNotExist.Value(),
                                               AuthenticationMessageHelper.ResponseMessages));
            }

            var passwordBanedList = _options.Value.PasswordsBanList;

            if (passwordBanedList.Any(d => d == request.NewPassword))
            {
                return(response.ReturnWithCode(AuthenticationMessageHelper.Code.ChangeMyUserPasswordSimplePass.Value(),
                                               AuthenticationMessageHelper.ResponseMessages));
            }

            if (user.PasswordHash != _securityService.GetSha256Hash(request.OldPassword))
            {
                return(response.ReturnWithCode(AuthenticationMessageHelper.Code.ChangeMyUserPasswordInvalidOldPassword.Value(),
                                               AuthenticationMessageHelper.ResponseMessages));
            }

            user.PasswordHash = _securityService.GetSha256Hash(request.NewPassword);

            await _unitOfWork.SaveChangesAsync();

            return(response.ReturnWithCode(AuthenticationMessageHelper.Code.ChangeMyUserPasswordSuccess.Value(),
                                           AuthenticationMessageHelper.ResponseMessages));
        }
예제 #2
0
 public async Task <IActionResult> ChangeMyUserPassword([FromBody] ChangeMyUserPasswordRequest request)
 {
     return(await ExecuteServiceAsync(() => _userService.ChangeMyUserPasswordAsync(request)));
 }