コード例 #1
0
        public async Task <JsonResult> UpdateAccountPassword(AccountSecurityVM security)
        {
            _logger.LogInformation("AccountController.UpdateAccountPassword - hidrogenianId=" + security.Id);

            var validation = await _reCaptchaService.IsHumanRegistration(security.CaptchaToken);

            if (!validation.Result)
            {
                return(new JsonResult(validation));
            }

            var isPasswordCorrect = await _authService.VerifyAccountPasswordFor(security.Id, security.Password);

            if (!isPasswordCorrect.HasValue || !isPasswordCorrect.Value)
            {
                return(new JsonResult(new { Result = RESULTS.FAILED, Message = "Your current Password seems to be incorrect. Please enter correct password and try again." }));
            }

            var verification = security.VerifyPassword();

            if (verification.Count != 0)
            {
                var messages = security.GenerateErrorMessages(verification);
                return(new JsonResult(new { Result = RESULTS.FAILED, Message = messages }));
            }

            var salted = _authService.GenerateHashedPasswordAndSalt(security.NewPassword);

            security.Password        = null;
            security.NewPassword     = salted.Key;
            security.PasswordConfirm = salted.Value;

            var result = await _accountService.UpdatePasswordForAccount(security);

            return(!result.HasValue ? new JsonResult(new { Result = RESULTS.FAILED, Message = "Unable to update password due to account not found. Please login again and try." })
                                    : (!result.Value ? new JsonResult(new { Result = RESULTS.FAILED, Message = "An error occurred while attempting to update your password. Please try again." })
                                                     : new JsonResult(new { Result = RESULTS.SUCCESS })));
        }
コード例 #2
0
        public async Task <bool?> UpdatePasswordForAccount(AccountSecurityVM security)
        {
            _logger.LogInformation("AccountService.UpdatePasswordForAccount - Service starts.");

            var dbAccount = await _dbContext.Hidrogenian.FindAsync(security.Id);

            if (dbAccount == null)
            {
                return(null);
            }

            dbAccount.PasswordHash = security.NewPassword;
            dbAccount.PasswordSalt = security.PasswordConfirm;

            _dbContext.Hidrogenian.Update(dbAccount);
            try {
                await _dbContext.SaveChangesAsync();
            } catch (Exception e) {
                _logger.LogError("AccountService.UpdatePasswordForAccount - Error: " + e);
                return(false);
            }

            return(true);
        }